Base class for models
Kind: global class
-
BaseModelSql
- new BaseModelSql(args)
-
.$db ⇒
Object
-
.transaction() ⇒
Promise.<Object>
-
.commit(trx) ⇒
Promise.<void>
-
.rollback(trx) ⇒
Promise.<void>
-
.isCompleted(trx) ⇒
Promise.<void>
-
.insert(data, [trx]) ⇒
Promise.<Array.<Object>>
|Promise.<Array.<Number>>
-
.updateByPk(id, data, [trx]) ⇒
Promise.<Number>
-
.delByPk(id, [trx]) ⇒
Promise.<Number>
-
.insertByFk(args, [trx]) ⇒
Promise.<Array.<Object>>
|Promise.<Array.<Object>>
-
.updateByFk(args, [trx]) ⇒
Promise.<Number>
-
.update(args, [trx]) ⇒
Promise.<Number>
-
.delByFk(args, [trx]) ⇒
Promise.<Number>
-
.del(args, [trx]) ⇒
Promise.<Number>
-
.insertb(data) ⇒
Promise.<Array.<Object>>
|Promise.<Array.<Number>>
-
.updateb(data) ⇒
Promise.<Array.<Number>>
-
.delb(ids) ⇒
Promise.<Array.<Number>>
-
.readByPk(id) ⇒
Promise.<Object>
-
.readByFk(args) ⇒
Promise.<Object>
-
.exists(id) ⇒
Promise.<boolean>
-
.existsByFk(id) ⇒
Promise.<boolean>
-
.raw(queryString, params) ⇒
Promise
-
.hasManyChildren(args) ⇒
Promise.<Array.<Object>>
-
.hasManyList(args) ⇒
Promise.<Array.<Object>>
-
.belongsTo(args) ⇒
Promise.<Array.<Object>>
-
.hasManyListGQL(args, ids) ⇒
Promise.<Object.<string, Array.<Object>>>
-
.hasManyListCount(args, ids) ⇒
Promise.<Object.<string, Array.<Object>>>
- .beforeInsert(data, trx)
- .afterInsert(response, trx)
- .errorInsert(err, data, trx)
- .beforeUpdate(data, trx)
- .afterUpdate(response, trx)
- .errorUpdate(err, data, trx)
- .beforeDelete(data, trx)
- .afterDelete(response, trx)
- .errorDelete(err, data, trx)
- .beforeInsertb(data, trx)
- .afterInsertb(response, trx)
- .errorInsertb(err, data, trx)
- .beforeUpdateb(data, trx)
- .afterUpdateb(response, trx)
- .errorUpdateb(err, data, trx)
- .beforeDeleteb(data, trx)
- .afterDeleteb(response, trx)
- .errorDeleteb(err, data, trx)
Returns: BaseModelSql
- Returns BaseModelSql reference.
Param | Type | Description |
---|---|---|
args | Object |
|
args.knex | Object |
Knex instance |
args.tableName | String |
table name |
args.columns | Array.<Object> |
columns |
args.pks | Array.<Object> |
primary keys |
args.hasMany | Array.<Object> |
has many relations |
args.belongsTo | Array.<Object> |
belongs to relations |
args.hooks | Object |
afterInsert, beforeInsert, errorInsert, afterUpdate, beforeUpdate, errorUpdate, afterDelete, beforeDelete, errorDelete |
Kind: instance property of BaseModelSql
Returns: Object
- knex instance attached to a table
Returns a transaction reference
Kind: instance method of BaseModelSql
Returns: Promise.<Object>
- Transaction reference
Commit transaction
Kind: instance method of BaseModelSql
Param | Type | Description |
---|---|---|
trx | Object |
Transaction reference |
Rollback transaction
Kind: instance method of BaseModelSql
Param | Type | Description |
---|---|---|
trx | Object |
Transaction reference |
Transaction completed
Kind: instance method of BaseModelSql
Param | Type | Description |
---|---|---|
trx | Object |
Transaction reference |
Creates row in table
Kind: instance method of BaseModelSql
Param | Type | Default | Description |
---|---|---|---|
data | Object |
row data | |
[trx] | Object |
|
knex transaction object |
Update table row data by primary key
Kind: instance method of BaseModelSql
Returns: Promise.<Number>
- 1 for success, 0 for failure
Param | Type | Default | Description |
---|---|---|---|
id | String |
primary key separated by ___ | |
data | Object |
table row data | |
[trx] | Object |
|
knex transaction object |
Delete table row data by primary key
Kind: instance method of BaseModelSql
Returns: Promise.<Number>
- 1 for success, 0 for failure
Param | Type | Default | Description |
---|---|---|---|
id | String |
primary key separated by ___ | |
[trx] | Object |
|
knex transaction object |
Creates row in this table under a certain parent
Kind: instance method of BaseModelSql
Todo
- [ ] should return inserted record
Param | Type | Description |
---|---|---|
args | Object |
|
args.data | Object |
row data |
args.parentId | String |
parent table id |
args.parentTableName | String |
parent table name |
[trx] | Object |
knex transaction object |
Update table row data by primary key and foreign key
Kind: instance method of BaseModelSql
Returns: Promise.<Number>
- 1 for success, 0 for failure
Param | Type | Description |
---|---|---|
args | Object |
|
args.id | String |
primary key separated by ___ |
args.parentId | String |
parent table id |
args.parentTableName | String |
parent table name |
args.data | Object |
table row data |
[trx] | Object |
knex transaction object |
Update table row data by using where clause
Kind: instance method of BaseModelSql
Returns: Promise.<Number>
- number of rows affected
Param | Type | Description |
---|---|---|
args | Object |
|
args.where | String |
update where clause |
args.data | Object |
table row data |
[trx] | Object |
knex transaction object |
Delete table row data by primary key and foreign key
Kind: instance method of BaseModelSql
Returns: Promise.<Number>
- 1 for success, 0 for failure
Param | Type | Description |
---|---|---|
args | Object |
|
args.id | String |
primary key separated by ___ |
args.parentId | String |
parent table id |
args.parentTableName | String |
parent table name |
[trx] | Object |
knex transaction object |
Delete table row data by where conditions
Kind: instance method of BaseModelSql
Returns: Promise.<Number>
- number of deleted records
Param | Type | Description |
---|---|---|
args | Object |
|
args.where | String |
where clause for deleting |
[trx] | Object |
knex transaction object |
Creates multiple rows in table
Kind: instance method of BaseModelSql
Param | Type | Description |
---|---|---|
data | Array.<Object> |
row data |
Update bulk - happens within a transaction
Kind: instance method of BaseModelSql
Returns: Promise.<Array.<Number>>
- - 1 for success, 0 for failure
Param | Type | Description |
---|---|---|
data | Array.<Object> |
table rows to be updated |
Bulk delete happens within a transaction
Kind: instance method of BaseModelSql
Returns: Promise.<Array.<Number>>
- - 1 for success, 0 for failure
Param | Type | Description |
---|---|---|
ids | Array.<Object> |
rows to be deleted |
Reads table row data
Kind: instance method of BaseModelSql
Returns: Promise.<Object>
- Table row data
Param | Type | Description |
---|---|---|
id | String |
primary key separated by ___ |
Reads table row data under a certain parent
Kind: instance method of BaseModelSql
Returns: Promise.<Object>
- returns row
Param | Type | Description |
---|---|---|
args | Object |
|
args.id | Object |
primary key separated by ___ |
args.parentId | String |
parent table id |
args.parentTableName | String |
parent table name |
Table row exists
Kind: instance method of BaseModelSql
Returns: Promise.<boolean>
- - true for exits and false for none
Param | Type | Description |
---|---|---|
id | String |
___ separated primary key string |
Table row exists
Kind: instance method of BaseModelSql
Returns: Promise.<boolean>
- - true for exits and false for none
Param | Type | Description |
---|---|---|
id | String |
___ separated primary key string |
Runs raw query on database
Kind: instance method of BaseModelSql
Returns: Promise
- - return raw data from database driver
Param | Type | Description |
---|---|---|
queryString | String |
query string |
params | Array.<Object> |
paramaterised values in an array for query |
Gets child rows for a parent row in this table
Kind: instance method of BaseModelSql
Returns: Promise.<Array.<Object>>
- return child rows
Param | Type | Default | Description |
---|---|---|---|
args | Object |
||
args.child | String |
child table name | |
args.parentId | String |
pk | |
[args.fields] | String |
* |
commas separated column names of this table |
[args.where] | String |
where clause with conditions within () | |
[args.limit] | String |
number of rows to be limited (has default,min,max values in config) | |
[args.offset] | String |
offset from which to get the number of rows | |
[args.sort] | String |
comma separated column names where each column name is columnName ascending and -columnName is columnName descending |
Gets parent list along with children list
Kind: instance method of BaseModelSql
Param | Type | Default | Description |
---|---|---|---|
args | Object |
||
args.childs | String |
comma separated child table names | |
[args.fields] | String |
* |
commas separated column names of this table |
[args.fields*] | String |
* |
commas separated column names of child table(* is a natural number 'i' where i is index of child table in comma separated list) |
[args.where] | String |
where clause with conditions within () | |
[args.where*] | String |
where clause with conditions within ()(* is a natural number 'i' where i is index of child table in comma separated list) | |
[args.limit] | String |
number of rows to be limited (has default,min,max values in config) | |
[args.limit*] | String |
number of rows to be limited of child table(* is a natural number 'i' where i is index of child table in comma separated list) | |
[args.offset] | String |
offset from which to get the number of rows | |
[args.offset*] | String |
offset from which to get the number of rows of child table(* is a natural number 'i' where i is index of child table in comma separated list) | |
[args.sort] | String |
comma separated column names where each column name is columnName ascending and -columnName is columnName descending | |
[args.sort*] | String |
comma separated column names where each column name is columnName ascending and -columnName is columnName descending(* is a natural number 'i' where i is index of child table in comma separated list) |
Gets child list along with its parent
Kind: instance method of BaseModelSql
Param | Type | Default | Description |
---|---|---|---|
args | Object |
||
args.parents | String |
comma separated parent table names | |
[args.fields] | String |
* |
commas separated column names of this table |
[args.fields*] | String |
* |
commas separated column names of parent table(* is a natural number 'i' where i is index of child table in comma separated list) |
[args.where] | String |
where clause with conditions within () | |
[args.limit] | String |
number of rows to be limited (has default,min,max values in config) | |
[args.offset] | String |
offset from which to get the number of rows | |
[args.sort] | String |
comma separated column names where each column name is columnName ascending and -columnName is columnName descending |
Returns key value paired grouped children list
Kind: instance method of BaseModelSql
Returns: Promise.<Object.<string, Array.<Object>>>
- key will be parent pk and value will be child list
Param | Type | Description |
---|---|---|
args | Object |
|
args.child | String |
child table name |
ids | Array.<String> |
array of parent primary keys |
[args.where] | String |
where clause with conditions within () |
[args.limit] | String |
number of rows to be limited (has default,min,max values in config) |
[args.offset] | String |
offset from which to get the number of rows |
[args.sort] | String |
comma separated column names where each column name is columnName ascending and -columnName is columnName descending |
Returns key value paired grouped children list
Kind: instance method of BaseModelSql
Returns: Promise.<Object.<string, Array.<Object>>>
- key will be parent pk and value will be child list
Param | Type | Description |
---|---|---|
args | Object |
|
args.child | String |
child table name |
ids | Array.<String> |
array of parent primary keys |
[args.where] | String |
where clause with conditions within () |
[args.limit] | String |
number of rows to be limited (has default,min,max values in config) |
[args.offset] | String |
offset from which to get the number of rows |
[args.sort] | String |
comma separated column names where each column name is columnName ascending and -columnName is columnName descending |
Before Insert is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
data | Object |
insert data |
trx | Object |
knex transaction reference |
After Insert is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
response | Object |
inserted data |
trx | Object |
knex transaction reference |
After Insert is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
err | Error |
Exception reference |
data | Object |
insert data |
trx | Object |
knex transaction reference |
Before Update is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
data | Object |
update data |
trx | Object |
knex transaction reference |
After Update is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
response | Object |
updated data |
trx | Object |
knex transaction reference |
Error update is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
err | Error |
Exception reference |
data | Object |
update data |
trx | Object |
knex transaction reference |
Before delete is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
data | Object |
delete data |
trx | Object |
knex transaction reference |
After Delete is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
response | Object |
Deleted data |
trx | Object |
knex transaction reference |
Error delete is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
err | Error |
Exception reference |
data | Object |
delete data |
trx | Object |
knex transaction reference |
Before insert bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
data | Array.<Object> |
insert data |
trx | Object |
knex transaction reference |
After insert bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
response | Array.<Object> |
inserted data |
trx | Object |
knex transaction reference |
Error insert bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
err | Error |
Exception reference |
data | Object |
delete data |
trx | Object |
knex transaction reference |
Before update bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
data | Array.<Object> |
update data |
trx | Object |
knex transaction reference |
After update bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
response | Array.<Object> |
updated data |
trx | Object |
knex transaction reference |
Error update bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
err | Error |
Exception reference |
data | Array.<Object> |
delete data |
trx | Object |
knex transaction reference |
Before delete bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
data | Array.<Object> |
delete data |
trx | Object |
knex transaction reference |
After delete bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
response | Array.<Object> |
deleted data |
trx | Object |
knex transaction reference |
Error delete bulk is a hook which can be override in subclass
Kind: instance abstract method of BaseModelSql
Param | Type | Description |
---|---|---|
err | Error |
Exception reference |
data | Array.<Object> |
delete data |
trx | Object |
knex transaction reference |