new PostgresRepository(app, postgres, cacher, util)
Create repository
Parameters:
| Name | Type | Description |
|---|---|---|
app |
App | The application |
postgres |
Postgres | Postgres service |
cacher |
Cacher | Cacher service |
util |
Util | Util service |
Members
-
<static> provides :string
-
Service name is 'repositories.postgres'
Type:
- string
-
<static> requires :Array.<string>
-
Dependencies as constructor arguments
Type:
- Array.<string>
Methods
-
delete(model [, pg])
-
Delete a model
Parameters:
Name Type Argument Description modelBaseModel | number Model or ID pgPostgresClient | string <optional>
Will reuse the Postgres client provided, or if it is a string then will connect to this instance of Postgres. Returns:
Resolves to number of deleted records- Type
- Promise
-
findAll( [pg])
-
Find all models
Parameters:
Name Type Argument Description pgPostgresClient | string <optional>
Will reuse the Postgres client provided, or if it is a string then will connect to this instance of Postgres. Returns:
Resolves to array of models- Type
- Promise
-
find(id [, pg])
-
Find a model by ID
Parameters:
Name Type Argument Description idnumber ID to search by pgPostgresClient | string <optional>
Will reuse the Postgres client provided, or if it is a string then will connect to this instance of Postgres. Returns:
Resolves to array of models- Type
- Promise
-
save(model [, pg])
-
Save model
Parameters:
Name Type Argument Description modelBaseModel The model pgPostgresClient | string <optional>
Will reuse the Postgres client provided, or if it is a string then will connect to this instance of Postgres. Returns:
Resolves to record ID- Type
- Promise
-
search( [options] [, pg])
-
Search repository
Parameters:
Name Type Argument Description optionsobject <optional>
Properties
Name Type Argument Default Description tablestring <optional>
Table or view name fieldsArray.<string> <optional>
Fields to retrieve whereArray.<string> <optional>
SQL WHERE clause: will be joined with 'AND' paramsArray <optional>
Bound parameters of WHERE (referenced as $1, $2, ... in SQL) sortstring <optional>
['id asc'] Used in ORDER BY if provided pageSizenumber <optional>
0 Used in LIMIT, 0 = all records pageNumbernumber <optional>
1 Used in OFFSET infoOnlyboolean <optional>
false Retrieve data rows or not pgPostgresClient | string <optional>
Will reuse the Postgres client provided, or if string then will connect to this instance of Postgres. Returns:
Returns promise resolving to the following:{ totalRows: 1, // total rows in result totalPages: 1, // total number of pages pageSize: 0, // page size pageNumber: 1, // returned page number sort: [ ... ], // keys used to sort the result data: [ ... ], // resulting raw SQL rows as an array of models }- Type
- Promise