new EntityRepository(Entity, Mapping)
Parameters:
| Name | Type | Description |
|---|---|---|
Entity |
Class | function | Class or constructor function. Entities from this repository will be instances of this Type |
Mapping |
BookshelfMapping | Compiled Mapping which describes this type and its relations |
- Source:
Methods
-
newEntity( [flatModel])
-
Create new instance of Entity.
Parameters:
Name Type Argument Description flatModelobject <optional>
Simple object representation of Entity, e.g. after deserializing JSON. Properties missing in Mapping are dropped
- Source:
Returns:
- Instance of Entity, with given properties if any
- Type
- Entity
-
findOne(id [, options])
-
Fetch one Entity from this Repository
Parameters:
Name Type Argument Default Description idID Identifier of Entity, specified in Mapping by "identifiedBy"
optionsobject <optional>
null Bookshelf fetch options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
excludeArray.<string> <optional>
Relation names to exclude, deep relations in dot notation. Specify wildcards using "*"
- Source:
Returns:
- Returns Promise resolved with entity, or null if not found
- Type
- Promise.<(Entity|null)>
-
findAll(ids [, options])
-
Fetch all Entities, or Entities with given Ids from this Repository
Parameters:
Name Type Argument Default Description idsArray.<ID> Identifiers of Entities, specified in Mapping by "identifiedBy"
optionsobject <optional>
null Bookshelf fetch options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
excludeArray.<string> <optional>
Relation names to exclude, deep relations in dot notation. Specify wildcards using "*"
- Source:
Returns:
- Returns Promise resolved with array of entities, or empty list if not found.
If ids were specified, Entities are sorted statically by given ids
- Type
- Promise.<Array.<Entity>>
-
findAllWhere(q [, options])
-
Fetch Entities using a query
Parameters:
Name Type Argument Default Description qfunction Callback, used as Bookshelf/Knex where condition.
optionsobject <optional>
null Bookshelf fetch options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
excludeArray.<string> <optional>
Relation names to exclude, deep relations in dot notation. Specify wildcards using "*"
- Source:
Returns:
- Returns Promise resolved with array of entities, or empty list if not found.
- Type
- Promise.<Array.<Entity>>
-
findWhere(q [, options])
-
Fetch Entity using a query
Parameters:
Name Type Argument Default Description qfunction Callback, used as Bookshelf/Knex where condition.
optionsobject <optional>
null Bookshelf fetch options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
excludeArray.<string> <optional>
Relation names to exclude, deep relations in dot notation. Specify wildcards using "*"
- Source:
Returns:
- Returns Promise resolved with entity, or null if not found
- Type
- Promise.<(Entity|null)>
-
save(entity [, options])
-
Save one or multiple Entities to this Repository
Parameters:
Name Type Argument Default Description entityEntity | Array.<Entity> Entity or Entities to save
optionsobject <optional>
null Bookshelf save options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
methodstring <optional>
Specify "update" or "insert". Defaults to "update", or "insert" if Id is null
- Source:
Returns:
- Returns Promise resolved with saved entity, or array of saved entities
- Type
- Promise.<(Entity|Array.<Entity>)>
-
afterSave(id)
-
Hook, is called once after every successful save operation
Parameters:
Name Type Description idID Identifier of saved Entity
- Source:
-
remove(entity [, options])
-
Remove one or multiple Entities from this Repository
Parameters:
Name Type Argument Default Description entityEntity | Array.<Entity> | ID | Array.<ID> Entity or Entities, Id or Ids to remove
optionsobject <optional>
null Bookshelf save options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
- Source:
Returns:
- Returns Promise resolved after removal
- Type
- Promise.<Void>
-
afterRemove(id)
-
Hook, is called once after every successful remove operation
Parameters:
Name Type Description idID Identifier of removed Entity
- Source:
-
executeTransactional(operation, options)
-
Execute an operation in a running or new transaction
Parameters:
Name Type Default Description operationfunction Callback to execute in a transaction
optionsobject null Bookshelf options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
- Source:
Returns:
- Promise resolved with result of operation. If operation fails, Promise is rejected
- Type
- Promise.<*>
-
addTransactionToQuery(query, options)
-
Add an already started transaction to given query. If not yet started, no transaction will be added
Parameters:
Name Type Argument Description options.transactingTransaction <optional>
Add Transaction object to given query
queryKnexQuery Add transaction to query, if one was started.
optionsobject Bookshelf options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
- Source:
Returns:
query - Returns KnexQuery for chaining
- Type
- KnexQuery
-
exists(id [, options])
-
Returns whether an Entity with the given Identifier exists.
Parameters:
Name Type Argument Default Description idID Identifier
optionsobject <optional>
null Bookshelf save options
Properties
Name Type Argument Description transactingTransaction <optional>
Run in given transaction
transactionalboolean <optional>
Run in a transaction, start new one if not already transacting
- Source:
Returns:
- Returns Promise resolved with flag indicating whether an Entity with the given Identifier exists
- Type
- Promise.<boolean>