Skip to content

Instantly share code, notes, and snippets.

@mducharme
Last active October 6, 2017 13:58
Show Gist options
  • Save mducharme/91691c1f4e292f77185798faf23fb242 to your computer and use it in GitHub Desktop.
Save mducharme/91691c1f4e292f77185798faf23fb242 to your computer and use it in GitHub Desktop.
  • ExpressionInterface

    • JsonSerializable (jsonSerialize())
    • active()
    • raw()
    • data()
    • GroupInterface
      • Iterator / Traversable
      • type()
      • items()
      • conjunction()
      • add(ExpressionInterface $expression)
    • FilterInterface
      • property()
      • val()
      • operator()
    • OrderInterface
      • property()
      • mode()
      • value()
    • PaginationInterface
      • page()
      • num() (was: numPerPage())
    • QueryInterface
      • `filters()
      • orders()
      • pagination()
      • DatabaseQueryInterface
        • sql()
        • pdoStatement(PDO $pdo)
  • DatabaseExpression

    • DatabaseFilter
    • DatabaseOrder
    • DatabasePagination
    • DatabaseQuery
<?php
$query = new DatabaseQuery();
$query->setData([
'filters' => [
'property'=>'active',
'value' => 'true
],
'orders' => [
],
'pagination' => [
]
]);
$sql = $query->sql();
echo $sql['query'];
// Alternative ways...
$query = new DatabaseQuery([
]);
$query->filters()->add([
'property' =>
]);
$filter = new DatabaseFilter([
'property' => 'active',
'value' => true
]);
$query->filter()->add($filter);
// With new CollectionLoader
$loader = new \Charcoal\Model\Service\CollectionLoader([
'pdo' => $container['database'],
'model' => MyModel::class
]);
$transformer = function($model)
{
$model['new-property'] = rand(0,100);
return $model;
};
$models = $loader->loadModels($query, $transformer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment