0.3.1 • Published 4 years ago

xc-data-mapper v0.3.1

Weekly downloads
910
License
Apache-2.0
Repository
gitlab
Last release
4 years ago

Install & setup

API Reference

Base class for models

Kind: global class

new BaseModelSql(args)

Returns: BaseModelSql - Returns BaseModelSql reference.

ParamTypeDescription
argsObject
args.knexObjectKnex instance
args.tableNameStringtable name
args.columnsArray.<Object>columns
args.pksArray.<Object>primary keys
args.hasManyArray.<Object>has many relations
args.belongsToArray.<Object>belongs to relations
args.hooksObjectafterInsert, beforeInsert, errorInsert, afterUpdate, beforeUpdate, errorUpdate, afterDelete, beforeDelete, errorDelete

baseModelSql.$db ⇒ Object

Kind: instance property of BaseModelSql
Returns: Object - knex instance attached to a table

baseModelSql.transaction() ⇒ Promise.<Object>

Returns a transaction reference

Kind: instance method of BaseModelSql
Returns: Promise.<Object> - Transaction reference

baseModelSql.commit(trx) ⇒ Promise.<void>

Commit transaction

Kind: instance method of BaseModelSql

ParamTypeDescription
trxObjectTransaction reference

baseModelSql.rollback(trx) ⇒ Promise.<void>

Rollback transaction

Kind: instance method of BaseModelSql

ParamTypeDescription
trxObjectTransaction reference

baseModelSql.isCompleted(trx) ⇒ Promise.<void>

Transaction completed

Kind: instance method of BaseModelSql

ParamTypeDescription
trxObjectTransaction reference

baseModelSql.insert(data, trx) ⇒ Promise.<Array.<Object>> | Promise.<Array.<Number>>

Creates row in table

Kind: instance method of BaseModelSql

ParamTypeDefaultDescription
dataObjectrow data
trxObjectknex transaction object

baseModelSql.updateByPk(id, data, trx) ⇒ Promise.<Number>

Update table row data by primary key

Kind: instance method of BaseModelSql
Returns: Promise.<Number> - 1 for success, 0 for failure

ParamTypeDefaultDescription
idStringprimary key separated by ___
dataObjecttable row data
trxObjectknex transaction object

baseModelSql.delByPk(id, trx) ⇒ Promise.<Number>

Delete table row data by primary key

Kind: instance method of BaseModelSql
Returns: Promise.<Number> - 1 for success, 0 for failure

ParamTypeDefaultDescription
idStringprimary key separated by ___
trxObjectknex transaction object

baseModelSql.insertByFk(args, trx) ⇒ Promise.<Array.<Object>> | Promise.<Array.<Object>>

Creates row in this table under a certain parent

Kind: instance method of BaseModelSql
Todo

  • should return inserted record
ParamTypeDescription
argsObject
args.dataObjectrow data
args.parentIdStringparent table id
args.parentTableNameStringparent table name
trxObjectknex transaction object

baseModelSql.updateByFk(args, trx) ⇒ Promise.<Number>

Update table row data by primary key and foreign key

Kind: instance method of BaseModelSql
Returns: Promise.<Number> - 1 for success, 0 for failure

ParamTypeDescription
argsObject
args.idStringprimary key separated by ___
args.parentIdStringparent table id
args.parentTableNameStringparent table name
args.dataObjecttable row data
trxObjectknex transaction object

baseModelSql.update(args, trx) ⇒ Promise.<Number>

Update table row data by using where clause

Kind: instance method of BaseModelSql
Returns: Promise.<Number> - number of rows affected

ParamTypeDescription
argsObject
args.whereStringupdate where clause
args.dataObjecttable row data
trxObjectknex transaction object

baseModelSql.delByFk(args, trx) ⇒ Promise.<Number>

Delete table row data by primary key and foreign key

Kind: instance method of BaseModelSql
Returns: Promise.<Number> - 1 for success, 0 for failure

ParamTypeDescription
argsObject
args.idStringprimary key separated by ___
args.parentIdStringparent table id
args.parentTableNameStringparent table name
trxObjectknex transaction object

baseModelSql.del(args, trx) ⇒ Promise.<Number>

Delete table row data by where conditions

Kind: instance method of BaseModelSql
Returns: Promise.<Number> - number of deleted records

ParamTypeDescription
argsObject
args.whereStringwhere clause for deleting
trxObjectknex transaction object

baseModelSql.insertb(data) ⇒ Promise.<Array.<Object>> | Promise.<Array.<Number>>

Creates multiple rows in table

Kind: instance method of BaseModelSql

ParamTypeDescription
dataArray.<Object>row data

baseModelSql.updateb(data) ⇒ Promise.<Array.<Number>>

Update bulk - happens within a transaction

Kind: instance method of BaseModelSql
Returns: Promise.<Array.<Number>> - - 1 for success, 0 for failure

ParamTypeDescription
dataArray.<Object>table rows to be updated

baseModelSql.delb(ids) ⇒ Promise.<Array.<Number>>

Bulk delete happens within a transaction

Kind: instance method of BaseModelSql
Returns: Promise.<Array.<Number>> - - 1 for success, 0 for failure

ParamTypeDescription
idsArray.<Object>rows to be deleted

baseModelSql.readByPk(id) ⇒ Promise.<Object>

Reads table row data

Kind: instance method of BaseModelSql
Returns: Promise.<Object> - Table row data

ParamTypeDescription
idStringprimary key separated by ___

baseModelSql.readByFk(args) ⇒ Promise.<Object>

Reads table row data under a certain parent

Kind: instance method of BaseModelSql
Returns: Promise.<Object> - returns row

ParamTypeDescription
argsObject
args.idObjectprimary key separated by ___
args.parentIdStringparent table id
args.parentTableNameStringparent table name

baseModelSql.exists(id) ⇒ Promise.<boolean>

Table row exists

Kind: instance method of BaseModelSql
Returns: Promise.<boolean> - - true for exits and false for none

ParamTypeDescription
idString___ separated primary key string

baseModelSql.existsByFk(id) ⇒ Promise.<boolean>

Table row exists

Kind: instance method of BaseModelSql
Returns: Promise.<boolean> - - true for exits and false for none

ParamTypeDescription
idString___ separated primary key string

baseModelSql.raw(queryString, params) ⇒ Promise

Runs raw query on database

Kind: instance method of BaseModelSql
Returns: Promise - - return raw data from database driver

ParamTypeDescription
queryStringStringquery string
paramsArray.<Object>paramaterised values in an array for query

baseModelSql.hasManyChildren(args) ⇒ Promise.<Array.<Object>>

Gets child rows for a parent row in this table

Kind: instance method of BaseModelSql
Returns: Promise.<Array.<Object>> - return child rows

ParamTypeDefaultDescription
argsObject
args.childStringchild table name
args.parentIdStringpk
args.fieldsString*commas separated column names of this table
args.whereStringwhere clause with conditions within ()
args.limitStringnumber of rows to be limited (has default,min,max values in config)
args.offsetStringoffset from which to get the number of rows
args.sortStringcomma separated column names where each column name is columnName ascending and -columnName is columnName descending

baseModelSql.hasManyList(args) ⇒ Promise.<Array.<Object>>

Gets parent list along with children list

Kind: instance method of BaseModelSql

ParamTypeDefaultDescription
argsObject
args.childsStringcomma separated child table names
args.fieldsString*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.whereStringwhere clause with conditions within ()
args.where*Stringwhere clause with conditions within ()(* is a natural number 'i' where i is index of child table in comma separated list)
args.limitStringnumber of rows to be limited (has default,min,max values in config)
args.limit*Stringnumber 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.offsetStringoffset from which to get the number of rows
args.offset*Stringoffset 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.sortStringcomma separated column names where each column name is columnName ascending and -columnName is columnName descending
args.sort*Stringcomma 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)

baseModelSql.belongsTo(args) ⇒ Promise.<Array.<Object>>

Gets child list along with its parent

Kind: instance method of BaseModelSql

ParamTypeDefaultDescription
argsObject
args.parentsStringcomma separated parent table names
args.fieldsString*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.whereStringwhere clause with conditions within ()
args.limitStringnumber of rows to be limited (has default,min,max values in config)
args.offsetStringoffset from which to get the number of rows
args.sortStringcomma separated column names where each column name is columnName ascending and -columnName is columnName descending

baseModelSql.hasManyListGQL(args, ids) ⇒ Promise.<Object.<string, Array.<Object>>>

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

ParamTypeDescription
argsObject
args.childStringchild table name
idsArray.<String>array of parent primary keys
args.whereStringwhere clause with conditions within ()
args.limitStringnumber of rows to be limited (has default,min,max values in config)
args.offsetStringoffset from which to get the number of rows
args.sortStringcomma separated column names where each column name is columnName ascending and -columnName is columnName descending

baseModelSql.hasManyListCount(args, ids) ⇒ Promise.<Object.<string, Array.<Object>>>

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

ParamTypeDescription
argsObject
args.childStringchild table name
idsArray.<String>array of parent primary keys
args.whereStringwhere clause with conditions within ()
args.limitStringnumber of rows to be limited (has default,min,max values in config)
args.offsetStringoffset from which to get the number of rows
args.sortStringcomma separated column names where each column name is columnName ascending and -columnName is columnName descending

baseModelSql.beforeInsert(data, trx)

Before Insert is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
dataObjectinsert data
trxObjectknex transaction reference

baseModelSql.afterInsert(response, trx)

After Insert is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
responseObjectinserted data
trxObjectknex transaction reference

baseModelSql.errorInsert(err, data, trx)

After Insert is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
errErrorException reference
dataObjectinsert data
trxObjectknex transaction reference

baseModelSql.beforeUpdate(data, trx)

Before Update is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
dataObjectupdate data
trxObjectknex transaction reference

baseModelSql.afterUpdate(response, trx)

After Update is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
responseObjectupdated data
trxObjectknex transaction reference

baseModelSql.errorUpdate(err, data, trx)

Error update is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
errErrorException reference
dataObjectupdate data
trxObjectknex transaction reference

baseModelSql.beforeDelete(data, trx)

Before delete is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
dataObjectdelete data
trxObjectknex transaction reference

baseModelSql.afterDelete(response, trx)

After Delete is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
responseObjectDeleted data
trxObjectknex transaction reference

baseModelSql.errorDelete(err, data, trx)

Error delete is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
errErrorException reference
dataObjectdelete data
trxObjectknex transaction reference

baseModelSql.beforeInsertb(data, trx)

Before insert bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
dataArray.<Object>insert data
trxObjectknex transaction reference

baseModelSql.afterInsertb(response, trx)

After insert bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
responseArray.<Object>inserted data
trxObjectknex transaction reference

baseModelSql.errorInsertb(err, data, trx)

Error insert bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
errErrorException reference
dataObjectdelete data
trxObjectknex transaction reference

baseModelSql.beforeUpdateb(data, trx)

Before update bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
dataArray.<Object>update data
trxObjectknex transaction reference

baseModelSql.afterUpdateb(response, trx)

After update bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
responseArray.<Object>updated data
trxObjectknex transaction reference

baseModelSql.errorUpdateb(err, data, trx)

Error update bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
errErrorException reference
dataArray.<Object>delete data
trxObjectknex transaction reference

baseModelSql.beforeDeleteb(data, trx)

Before delete bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
dataArray.<Object>delete data
trxObjectknex transaction reference

baseModelSql.afterDeleteb(response, trx)

After delete bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
responseArray.<Object>deleted data
trxObjectknex transaction reference

baseModelSql.errorDeleteb(err, data, trx)

Error delete bulk is a hook which can be override in subclass

Kind: instance abstract method of BaseModelSql

ParamTypeDescription
errErrorException reference
dataArray.<Object>delete data
trxObjectknex transaction reference
0.3.1

4 years ago

0.3.0

4 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.15

5 years ago

0.0.16

5 years ago

0.0.18

5 years ago

0.0.14

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.6

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago