New in package 166
Syntax
Database.repository(type_name)
Database.repository(type_name).where(condition)
Description
Enumerable object used to query and modify database entities.
Methods
See also Enumerable Object Methods.
Crud
Method | Description |
---|---|
[create]([initial_data]) | Creates a new entity and pre-populates fields with the query criteria values. |
add([initial_data]) add(entity) |
Adds the new entity to the repository. The entity will be added to the database on [Database.saveChanges()]. |
[get](id[, ifNotExists]) | Returns an entity by entity id. Throws an exception if no such entity has been found and ifNotExists parameter has not been specified. |
[delete](entity) | Deletes the entity from the repository. The entity will be deleted from the database on [Database.saveChanges()]. |
Queries
Method | Description |
---|---|
where(criteria) | Creates a Database.query enumerating all the objects fitting the criteria. The criteria is specified as { field_name: value }. |
where(sql_condition[, params]) | Creates a non-updateable Database.query enumerating all the objects fitting the sql_condition. Multiple where clauses can be chained together to create and conditions. |
[orderBy](field_name[, sort_order]) | Creates a Database.query ordering the repository objects by the specified field_name. |
[first]([n]) | If n is 1 or omitted, selects the first record, otherwise creates a Database.query selecting first n records. |
[last]([n]) | If n is 1 or omitted, selects the last record, otherwise creates a Database.query selecting last n records. |
[elementAt](position) | Returns an object by zero-based position. |
[range](start, count) | Creates a Database.query which will return count objects starting from zero-based start position. |
[with](hint[, ...]) | Creates a Database.query which will use provided hints. |
Projection
Method | Description |
---|---|
[select](field[, ...]) | Creates a Database.query selecting the specified fields. |
[distinct](field[, ...]) | Creates a Database.query selecting distinct values of the specified fields. |
Aggregate functions
Method | Description |
---|---|
[count]() | Returns the number of records. |
[max](field) | Finds the maximum value of the field. |
[min](field) | Finds the minimum value of the field. |
[sum](field) | Finds the sum of the field. |
[average](field) | Returns the average value of the field. |
Set functions
Method | Description |
---|---|
[any]([criteria]) | Returns true if there are any records matching the criteria. |
[all]([criteria]) | Returns true if all the records match the criteria. |
Properties
Property | Description |
---|---|
type | Type information |
repository | Repository object |
Examples
Or:
Multiple Where Clauses
This is equivalent to: