# new RawBaseService(options)
Create a service instance.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
Object
|
|
repository |
Object
|
|
entityClass |
function
|
Methods
# async activate(id, optsopt)
Activate a record by its ID. Throws if not found.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
string
|
number
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async assertExists(where, optsopt)
Assert that at least one record exists for a where clause. Throws an error if not found.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
where |
Object
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async create(data, optsopt)
Create a record. Accepts either a POJO or an Entity instance.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
data |
Object
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async cursorPage(where, order, opts)
Cursor-based pagination passthrough. Defers to repository.cursorPage where the actual implementation will live. Returns { results, nextCursor, prevCursor } when implemented in repository.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
where |
Object
|
|||
order |
Array
|
|||
opts |
Object
|
|||
limit |
number
|
<optional> |
20 | |
cursor |
string
|
null
|
<optional> |
null | |
trx |
Object
|
<optional> |
# async deactivate(id, optsopt)
Deactivate a record by its ID. Throws if not found.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
string
|
number
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async delete(id, optsopt)
Delete a record by its ID. Returns the number of rows deleted.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
string
|
number
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async exists(where, optsopt)
Check if a record exists for a where clause. Returns true or false.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
where |
Object
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async getActive(whereopt, optsopt)
Get active records, optionally filtered by additional WHERE criteria. Returns an array of Entity instances.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
where |
Object
|
<optional> |
{} | Additional WHERE clause to filter results |
opts |
Object
|
<optional> |
||
trx |
Object
|
<optional> |
# async getAll(optsopt)
Get all records. Returns an array of Entity instances.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async getById(id, optsopt)
Get a record by its ID. Returns an Entity instance or null.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
string
|
number
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# getDefaultGraphName() → {string}
Get the default graph name for expanded queries. Override in subclasses to provide a different default.
Default graph name.
string
# getGraphExpression(name) → {string}
Get the graph expression for a named graph. Override in subclasses to provide named graphs.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
Name of the graph. |
Graph expression.
string
# getGraphModifiers(name) → {Object.<string, function()>|undefined}
Get the graph modifiers for a named graph. Override in subclasses to provide named graph modifiers.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
Name of the graph. |
Graph modifiers.
Object.<string, function()>
|
undefined
# async getOne(where, optsopt)
Get a single record matching a where clause. Returns an Entity instance or null.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
where |
Object
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async getOneExpanded(where, optsopt) → {Promise.<*>}
Get a single record matching a where clause, including related data. Returns an Entity instance or null.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
where |
Object
|
|||
opts |
Object
|
<optional> |
||
graphName |
string
|
<optional> |
Name of the graph to use. |
|
includeHiddenFields |
boolean
|
<optional> |
false | Whether to include hidden fields. |
trx |
Object
|
<optional> |
Knex transaction. |
Entity instance or null
Promise.<*>
# async getOneWithRelations(where, graph, optsopt) → {Promise.<*>}
Get a single record matching a where clause, including related data. Returns an Entity instance or null.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
where |
Object
|
||
graph |
string
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
Entity instance or null
Promise.<*>
Example
const user = await userService.getOneWithRelations(
{ id: 1 },
'account, roles',
{ trx }
);
console.log(user.account, user.roles);
# async getWhere(where, optsopt)
!IMPORTANT: This method returns a maximum of 1000 records as a sanity check. If you need more, use paginate function instead. Get records matching a where clause. Returns an array of Entity instances.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
where |
Object
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async getWhereExpanded(where, optsopt) → {Promise.<Array.<*>>}
Get records matching a where clause, including related data. Returns an array of Entity instances.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
where |
Object
|
|||
opts |
Object
|
<optional> |
||
graphName |
string
|
<optional> |
Name of the graph to use. |
|
includeHiddenFields |
boolean
|
<optional> |
false | Whether to include hidden fields. |
trx |
Object
|
<optional> |
Knex transaction. |
Array of Entity instances
Promise.<Array.<*>>
# async getWhereWithRelations(where, graph, optsopt) → {Promise.<Array.<*>>}
Get records matching a where clause, including related data. Returns an array of Entity instances.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
where |
Object
|
||
graph |
string
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
Array of Entity instances
Promise.<Array.<*>>
Example
const users = await userService.getWhereWithRelations(
{ isActive: true },
'account, roles',
{ trx }
);
console.log(users[0].account, users[0].roles);
# isEntity(val) → {boolean}
Determine whether a value looks like one of our Entity instances. Uses presence of toJSON, hiddenFields marker, or class name suffix.
Parameters:
| Name | Type | Description |
|---|---|---|
val |
*
|
boolean
# async paginate(where, page, pageSize, optsopt)
Paginate records using the repository's offset/limit paging. Returns { results, total, page, pageSize, totalPages } with results as Entities.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
where |
Object
|
|||
page |
number
|
1 | 1-based page number |
|
pageSize |
number
|
10 | ||
opts |
Object
|
<optional> |
||
trx |
Object
|
<optional> |
# toPlain(val) → {*}
Convert an Entity to a POJO using toJSON, otherwise return the value unchanged. Dates inside entity.toJSON() are expected to be serialized consistently.
Parameters:
| Name | Type | Description |
|---|---|---|
val |
*
|
*
# async toggleActive(id, optsopt)
Toggle the active status of a record by its ID. Throws if not found.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
string
|
number
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async update(id, data, optsopt)
Update a record by its ID. Accepts either a POJO or an Entity instance for the update data.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
id |
string
|
number
|
||
data |
Object
|
||
opts |
Object
|
<optional> |
|
trx |
Object
|
<optional> |
# async upsert(data, whereClauseopt, optsopt)
Upsert a record based on a where clause. Accepts either a POJO or an Entity instance.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
data |
Object
|
|||
whereClause |
Object
|
<optional> |
{} | |
opts |
Object
|
<optional> |
||
trx |
Object
|
<optional> |