roydejong/php-activerecord-utils

Utilities for composing queries in php-activerecord.

dev-master 2019-08-28 17:12 UTC

This package is auto-updated.

Last update: 2024-10-29 05:34:52 UTC


README

Simple utilities that make writing php-activerecord queries more convenient.

Latest Stable Version Build Status License

Getting started

Add this library as a Composer dependency:

composer require roydejong/php-activerecord-utils

Once included, you'll be able to autoload the desired classes from the ActiveRecordUtils\ namespace.

Conditions

ActiveRecordUtils\Composers\Conditions lets you elegantly compose readable conditions parameters for activerecord queries.

Basic usage

<?php

use ActiveRecordUtils\Composers\Conditions;

Conditions::make()
    ->where('employee_id = ?', 123)
    ->or('login_id = ?', 123)
    ->andWhere('is_enabled = 1')
    ->value();

// Returns: ["(employee_id = ? OR login_id = ?) AND (is_enabled = 1)", 123, 123]

Features

  • 📝 Better syntax: Programmatically compose your WHERE clauses with a syntax that's easier to read and more convenient to maintain.
  • Easy grouping: Use andWhere(), orWhere() to start a new parentheses group, or use and(), or() to add another condition to he current group.
  • Auto validation: Issues like wrong parameter count are automatically detected and produce convenient and readable error messages.