new MySQLRepository(app, mysql, util)
Create repository
Parameters:
Name | Type | Description |
---|---|---|
app |
App | The application |
mysql |
MySQL | MySQL service |
util |
Util | Util service |
Members
-
<static> provides :string
-
Service name is 'repositories.mysql'
Type:
- string
-
<static> requires :Array.<string>
-
Dependencies as constructor arguments
Type:
- Array.<string>
Methods
-
delete(model [, mysql])
-
Delete a model
Parameters:
Name Type Argument Description model
BaseModel | number Model or ID mysql
MySQLClient | string <optional>
Will reuse the MySQL client provided, or if it is a string then will connect to this instance of MySQL. Returns:
Resolves to number of deleted records- Type
- Promise
-
findAll( [mysql])
-
Find all models
Parameters:
Name Type Argument Description mysql
MySQLClient | string <optional>
Will reuse the MySQL client provided, or if it is a string then will connect to this instance of MySQL. Returns:
Resolves to array of models- Type
- Promise
-
find(id [, mysql])
-
Find a model by ID
Parameters:
Name Type Argument Description id
number ID to search by mysql
MySQLClient | string <optional>
Will reuse the MySQL client provided, or if it is a string then will connect to this instance of MySQL. Returns:
Resolves to array of models- Type
- Promise
-
save(model [, mysql])
-
Save model
Parameters:
Name Type Argument Description model
BaseModel The model mysql
MySQLClient | string <optional>
Will reuse the MySQL client provided, or if it is a string then will connect to this instance of MySQL. Returns:
Resolves to record ID- Type
- Promise
-
search( [options] [, mysql])
-
Search repository
Parameters:
Name Type Argument Description options
object <optional>
Properties
Name Type Argument Default Description table
string <optional>
Table or view name fields
Array.<string> <optional>
Fields to retrieve where
Array.<string> <optional>
SQL WHERE clause: will be joined with 'AND' params
Array <optional>
Bound parameters of WHERE (referenced as $1, $2, ... in SQL) sort
string <optional>
['id asc'] Used in ORDER BY if provided pageSize
number <optional>
0 Used in LIMIT, 0 = all records pageNumber
number <optional>
1 Used in OFFSET infoOnly
boolean <optional>
false Retrieve data rows or not mysql
MySQLClient | string <optional>
Will reuse the MySQL client provided, or if string then will connect to this instance of MySQL. 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