Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Commit

Permalink
Documentation etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
nielssp committed Feb 13, 2016
1 parent 94c5478 commit 911d83f
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 57 deletions.
31 changes: 31 additions & 0 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,35 @@ public function getShema();
* @return Record A record.
*/
public function create(array $data = array(), $allowedFields = null);

/**
* Make a selection that selects a single record.
* @param Record $record
* A record.
* @return Query\AnySelectable A selection.
*/
public function selectRecord(Record $record);

/**
* Make a selection that selects everything except for a single record.
*
* @param Record $record
* A record.
* @return Query\AnySelectable A selection.
*/
public function selectNotRecord(Record $record);

/**
* Find a record by its primary key. If the primary key
* consists of multiple fields, this function expects a
* parameter for each field (in alphabetical order).
* @param mixed $primary
* Value of primary key.
* @param mixed ...$primary
* For multifield primary key.
* @return Record|null A single matching record or null if it doesn't exist.
* @throws InvalidArgumentException If number of parameters does not
* match size of primary key.
*/
public function find($primary);
}
13 changes: 13 additions & 0 deletions src/Query/AnySelectable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
// Jivoo
// Copyright (c) 2015 Niels Sonnich Poulsen (http://nielssp.dk)
// Licensed under the MIT license.
// See the LICENSE file or http://opensource.org/licenses/MIT for more information.
namespace Jivoo\Data\Query;

/**
* A record selection with a predicate, an ordering and a limit.
*/
interface AnySelectable extends Updatable, Readable, Deletable
{
}
12 changes: 6 additions & 6 deletions src/Query/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
/**
* An interface for combining expressions using boolean logic.
*
* @method Boolean and(Expression|string $expr, mixed $vars,... ) AND operator.
* @method Boolean or(Expression|string $expr, mixed $vars,... ) OR operator.
* @method static and(Expression|string $expr, mixed $vars,... ) AND operator.
* @method static or(Expression|string $expr, mixed $vars,... ) OR operator.
*/
interface Boolean
{
Expand All @@ -21,7 +21,7 @@ interface Boolean
* Method name ('and' or 'or')
* @param mixed[] $args
* List of parameters
* @return Boolean Expression.
* @return static
*/
public function __call($method, $args);

Expand All @@ -33,7 +33,7 @@ public function __call($method, $args);
* @param mixed $vars,...
* Additional values to replace placeholders in
* $expr with.
* @return Boolean Expression.
* @return static
*/
public function where($expr);

Expand All @@ -45,7 +45,7 @@ public function where($expr);
* @param mixed $vars,...
* Additional values to replace placeholders in
* $expr with.
* @return Boolean Expression.
* @return static
*/
public function andWhere($expr);

Expand All @@ -57,7 +57,7 @@ public function andWhere($expr);
* @param mixed $vars,...
* Additional values to replace placeholders in
* $expr with.
* @return Boolean Expression.
* @return static
*/
public function orWhere($expr);
}
11 changes: 4 additions & 7 deletions src/Query/Builders/SelectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

use Jivoo\Data\DataSource;
use Jivoo\Data\DataType;
use Jivoo\Data\Model;
use Jivoo\Data\Query\Deletable;
use Jivoo\Data\Query\Readable;
use Jivoo\Data\Query\AnySelectable;
use Jivoo\Data\Query\ReadSelection;
use Jivoo\Data\Query\Updatable;
use Jivoo\Data\Query\UpdateSelection;
use Jivoo\Data\Record;
use Jivoo\Data\Schema;
Expand All @@ -21,7 +18,7 @@
* Will transform into a more specific selection based
* on use.
*/
class SelectionBuilder extends SelectionBase implements Readable, ReadSelection, Updatable, UpdateSelection, Deletable
class SelectionBuilder extends SelectionBase implements AnySelectable, ReadSelection, UpdateSelection
{

/**
Expand Down Expand Up @@ -99,9 +96,9 @@ public function getData()
/**
* Copy attributes into a basic selection.
*
* @param BasicSelectionBase $copy
* @param SelectionBase $copy
* A basic selection.
* @return BasicSelectionBase A basic selection.
* @return SelectionBase A basic selection.
*/
private function copyBasicAttr(SelectionBase $copy)
{
Expand Down
22 changes: 11 additions & 11 deletions src/Query/Readable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface Readable extends Selectable, \IteratorAggregate, \Countable
*
* @param int $offset
* Offset.
* @return Readable A readable selection.
* @return static
*/
public function offset($offset);

Expand All @@ -29,7 +29,7 @@ public function offset($offset);
*
* @param string $alias
* Alias.
* @return Readable A readable selection.
* @return static
*/
public function alias($alias);

Expand All @@ -49,26 +49,26 @@ public function select($expression, $alias = null);
/**
* Append an extra virtual field to the returned records.
*
* @param string $alias
* @param string $field
* Name of new field.
* @param Expression|string $expression
* Expression for field, e.g. 'COUNT(*)'.
* @param DataType|null $type
* Optional type of field.
* @return ReadSelection A read selection.
* @return static
*/
public function with($field, $expression, DataType $type = null);

/**
* Append an extra virtual field (with a record as the value) to the returned
* records.
*
* @param string $alias
* @param string $field
* Name of new field, expects the associated model to be
* aliased with the same name.
* @param Schema $schema
* Schema of associated record.
* @return Readable A readable selection.
* @return static
*/
public function withRecord($field, Schema $schema);

Expand All @@ -80,7 +80,7 @@ public function withRecord($field, Schema $schema);
* names.
* @param Expression|string $predicate
* Grouping predicate.
* @return Readable A readable selection.
* @return static
*/
public function groupBy($columns, $predicate = null);

Expand All @@ -93,7 +93,7 @@ public function groupBy($columns, $predicate = null);
* Join condition.
* @param string $alias
* Alias for joined model/table.
* @return Readable A readable selection.
* @return static
*/
public function innerJoin(DataSource $other, $condition, $alias = null);

Expand All @@ -106,7 +106,7 @@ public function innerJoin(DataSource $other, $condition, $alias = null);
* Join condition.
* @param string $alias
* Alias for joined model/table.
* @return Readable A readable selection.
* @return static
*/
public function leftJoin(DataSource $other, $condition, $alias = null);

Expand All @@ -119,7 +119,7 @@ public function leftJoin(DataSource $other, $condition, $alias = null);
* Join condition.
* @param string $alias
* Alias for joined model/table.
* @return Readable A readable selection.
* @return static
*/
public function rightJoin(DataSource $other, $condition, $alias = null);

Expand All @@ -129,7 +129,7 @@ public function rightJoin(DataSource $other, $condition, $alias = null);
*
* @param bool $distinct
* Whether to fetch only distinct records.
* @return Readable A readable selection.
* @return static
*/
public function distinct($distinct = true);

Expand Down
31 changes: 16 additions & 15 deletions src/Query/ReadableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait ReadableTrait
*
* @param int $offset
* Offset.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function offset($offset)
{
Expand All @@ -33,7 +33,7 @@ public function offset($offset)
*
* @param string $alias
* Alias.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function alias($alias)
{
Expand All @@ -44,12 +44,13 @@ public function alias($alias)
/**
* Make a projection.
*
* @param string|string[]|array $expression
* Expression or array of expressions
* and aliases
* @param string|string[]|Expression|Expression[] $expression
* Expression or array of expressions (if the keys are strings,
* they are used as aliases).
* @param string $alias
* Alias.
* @return array[] List of associative arrays
* @return \Iterator A {@see Record} iterator.
* @todo Rename to 'project' ?
*/
public function select($expression, $alias = null)
{
Expand All @@ -62,11 +63,11 @@ public function select($expression, $alias = null)
*
* @param string $alias
* Name of new field.
* @param string $expression
* @param Expression|string $expression
* Expression for field, e.g. 'COUNT(*)'.
* @param DataType|null $type
* Optional type of field.
* @return ReadSelection A read selection.
* @return ReadSelectionBuilder A read selection.
*/
public function with($field, $expression, DataType $type = null)
{
Expand All @@ -78,12 +79,12 @@ public function with($field, $expression, DataType $type = null)
* Append an extra virtual field (with a record as the value) to the returned
* records.
*
* @param string $alias
* @param string $field
* Name of new field, expects the associated model to be
* aliased with the same name.
* @param Schema $schema
* Schema of associated record.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function withRecord($field, Schema $schema)
{
Expand All @@ -99,7 +100,7 @@ public function withRecord($field, Schema $schema)
* names.
* @param Expression|string $predicate
* Grouping predicate.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function groupBy($columns, $predicate = null)
{
Expand All @@ -116,7 +117,7 @@ public function groupBy($columns, $predicate = null)
* Join condition.
* @param string $alias
* Alias for joined model/table.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function innerJoin(DataSource $other, $condition, $alias = null)
{
Expand All @@ -133,7 +134,7 @@ public function innerJoin(DataSource $other, $condition, $alias = null)
* Join condition.
* @param string $alias
* Alias for joined model/table.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function leftJoin(DataSource $other, $condition, $alias = null)
{
Expand All @@ -150,7 +151,7 @@ public function leftJoin(DataSource $other, $condition, $alias = null)
* Join condition.
* @param string $alias
* Alias for joined model/table.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function rightJoin(DataSource $other, $condition, $alias = null)
{
Expand All @@ -164,7 +165,7 @@ public function rightJoin(DataSource $other, $condition, $alias = null)
*
* @param bool $distinct
* Whether to fetch only distinct records.
* @return Readable A readable selection.
* @return ReadSelectionBuilder A read selection.
*/
public function distinct($distinct = true)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Query/Selectable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface Selectable extends Boolean
* @param Expression|string|null $expression
* Expression or column.
* If null all ordering will be removed from selection.
* @return Selectable A selection.
* @return static
*/
public function orderBy($expr);

Expand All @@ -26,14 +26,14 @@ public function orderBy($expr);
*
* @param Expression|string $expression
* Expression or column.
* @return Selectable A selection.
* @return static
*/
public function orderByDescending($expr);

/**
* Reverse the ordering.
*
* @return Selectable A selection.
* @return static
*/
public function reverseOrder();

Expand All @@ -42,7 +42,7 @@ public function reverseOrder();
*
* @param int $limit
* Number of records.
* @return Selectable A selection.
* @return static
*/
public function limit($limit);
}
Loading

0 comments on commit 911d83f

Please sign in to comment.