Kind: global class
Creates instance of Column
Param | Description |
---|---|
colName | name of the column |
sql | sql statement to create column |
validations | Array of validation functions, which throw error on validation failure |
formatter | Function which formats the column value, returns formatted value |
Gets column name
Kind: instance property of Column
Sets column name
Kind: instance property of Column
Gets the name of the column which is used to identify it in the sql
Kind: instance property of Column
Gets data type of the column
Kind: instance property of Column
Get sql statement which is used for column creation
Kind: instance property of Column
Runs column's formatter function for given value
Kind: instance method of Column
Returns:
formatted value
Param | Description |
---|---|
val | Any value for column input |
Runs column's validator functions for given value
Kind: instance method of Column
Param | Description |
---|---|
val | Any input value |
allInputs | Optional - inputs of other columns |
Kind: global class
- Model
- new Model(tableName, config)
- instance
- .tableName
- .table
- .beforeCreate(hook)
- .afterCreate(hook)
- .beforeUpdate(hook)
- .afterUpdate(hook)
- .beforeDestroy(hook)
- .afterDestroy(hook)
- .useHook(type, hook)
- .addForeignKey(foreignKey)
- .define(columns)
- .runWithHooks(operation, allInputs, fn) ⇒
- .findAll(options) ⇒
- .findAllWhere(whereClause, params) ⇒
- .findOne(needle) ⇒
- .findByPk(pkey) ⇒
- .create(data) ⇒
- .createMany(data) ⇒
- .update(data, where) ⇒
- .updateByPk(pkey, data) ⇒
- .patch(data, where) ⇒
- .patchByPk(pkey, data) ⇒
- .destroy(wher) ⇒
- .destroyByPk(pkey) ⇒
- static
Creates Model
instance
Param | Description |
---|---|
tableName | name of the database table |
config | model configurations |
Returns table name (with prefix)
Kind: instance property of Model
Returns Table
instance
Kind: instance property of Model
Creates a hook on model which runs before every insert
query
Kind: instance method of Model
Param | Description |
---|---|
hook | A function, which runs before every insertion in DB |
Creates a hook on model which runs after every insert
query
Kind: instance method of Model
Param | Description |
---|---|
hook | A function, which runs after every insertion in DB |
Creates a hook on model which runs before every update
query
Kind: instance method of Model
Param | Description |
---|---|
hook | A function, which runs before every update action in DB |
Creates a hook on model which runs after every update
query
Kind: instance method of Model
Param | Description |
---|---|
hook | A function, which runs after every update action in DB |
Creates a hook on model which runs before every delete
query
Kind: instance method of Model
Param | Description |
---|---|
hook | A function, which runs before every delete action in DB |
Creates a hook on model which runs after every delete
query
Kind: instance method of Model
Param | Description |
---|---|
hook | A function, which runs after every delete action in DB |
Adds specified hook to the Model, you can add as many hooks as you want
Kind: instance method of Model
Param | Description |
---|---|
type | Name of the hook, i.e 'beforeCreate,afterCreate,beforeUpdate,afterUpdate,beforeDestroy,afterDestroy |
hook | A function, to add as hook |
Creates foreign key on the Model
Kind: instance method of Model
Param | Description |
---|---|
foreignKey | An object containing foregin key config options |
Creates new tables with specified columns, or alters table if exists already (and alter:true
is set in model options)
Kind: instance method of Model
Param | Description |
---|---|
columns | An object cotaining columns schema and other options |
Takes user inputs, operation name and runs given function with all the hooks matching operation
Kind: instance method of Model
Returns:
any value returned by 'fn'
Param | Description |
---|---|
operation | Name of the database operation i.e 'Create, Update or Destroy' |
allInputs | User inputs |
fn | Function which does some database operation |
Finds all records in the table, or records matching given conditions
Kind: instance method of Model
Returns:
Found rows or empty array
Param | Description |
---|---|
options | Search options |
Finds all records matching given conditions
Kind: instance method of Model
Returns:
Found rows or empty array
Param | Description |
---|---|
whereClause | String containing where clause |
params | Values to replace in where clause |
Finds first record in the table, or record matching given conditions
Kind: instance method of Model
Returns:
Found row or null
Param | Description |
---|---|
needle | Object containing search conditions, column-value pairs |
Finds first record matching primary key
Kind: instance method of Model
Returns:
Found row or null
Param | Description |
---|---|
pkey | Primary key value |
Inserts new record in the table
Kind: instance method of Model
Returns:
Inserted row
Param | Description |
---|---|
data | Object containing data to insert, column-value pairs |
Inserts multiple records in the table
Kind: instance method of Model
Returns:
Inserted rows
Param | Description |
---|---|
data | Array of objects containing data to insert, column-value pairs |
Updates all records matching given conditions
Kind: instance method of Model
Returns:
Updated row
Param | Type | Description |
---|---|---|
data | Object containing data to update, column-value pairs |
|
where | whereOptions |
Object containing where options |
Updates first record matching given conditions
Kind: instance method of Model
Returns:
Updated row
Param | Description |
---|---|
pkey | Primary key value |
data | Object containing data to update, column-value pairs |
Partially updates all records matching given conditions
Kind: instance method of Model
Returns:
Updated row
Param | Type | Description |
---|---|---|
data | Object containing data to update, column-value pairs |
|
where | whereOptions |
Object containing where options |
Partially updates first record matching primary key
Kind: instance method of Model
Returns:
Updated row
Param | Description |
---|---|
pkey | Primary key value |
data | Object containing data to update, column-value pairs |
Deletes all records matching given conditions
Kind: instance method of Model
Returns:
Deleted rows
Param | Type | Description |
---|---|---|
wher | whereOptions |
e Object containing where options |
Deletes first record matching primary key
Kind: instance method of Model
Returns:
Deleted row
Param | Description |
---|---|
pkey | Primary key value |
Connects Model class to database using pg
, postgresql driver for nodejs
Kind: static method of Model
Param | Description |
---|---|
pgClient | client instance returned by |
Kind: global class
Takes an input object and a default object, merges both objects and generates new config, that can be accessed using config
property
Param | Description |
---|---|
input | input object |
defaults | default values for missing input values |
Returns merged input
and defaults
objects
Kind: instance property of Options
Kind: global class
- Query
- new Query(tableName, columns)
- instance
- .query
- .values
- .client
- .prepare(query, values, columns, where) ⇒
- .returning(cols) ⇒
- .count(column) ⇒
- .sum(column, where) ⇒
- .orderBy(columns) ⇒
- .groupBy(columns) ⇒
- .insert(values) ⇒
- .select(options) ⇒
- .update(values, columns, where) ⇒
- .delete(where) ⇒
- .tableExists() ⇒
- .columnExists(name, type) ⇒
- .constraintExists(name) ⇒
- .createTable(colsSchema) ⇒
- .addColumns(colsSchema) ⇒
- .dropTable() ⇒
- .dropColumn(name) ⇒
- .foreignKey(options) ⇒
- .run() ⇒
- .log() ⇒
- static
Creates a new Query
instance
Param | Description |
---|---|
tableName | Name of the table |
columns | Names of the columns for the table |
Gets query string
Kind: instance property of Query
Gets query values
Kind: instance property of Query
Gets the client object
Kind: instance property of Query
Prepares the query for the given values, that can be get with query.query
and query.values
Kind: instance method of Query
Returns:
reference to the instance
Param | Type | Description |
---|---|---|
query | Query string |
|
values | Values to be replaced in the query |
|
columns | Columns to be selected |
|
where | whereOptions |
Where clause |
Appends returning
clause to the query
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
cols | string (comma seperated) or an array of column names |
Creates a query to count values of given column in the table
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
column | Name of the column |
Create a query to sum the values of given column
Kind: instance method of Query
Returns:
reference to the instance
Param | Type | Description |
---|---|---|
column | Name of the column |
|
where | whereOptions |
An object of filters |
Appends order by
clause for given columns to the query
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
columns | List of column names, a comma seperated string, or an array of strings |
Appends group by
clause for given columns to the query
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
columns | List of column names, a comma seperated string, or an array of strings |
Creates an insert query
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
values | Values to be inserted |
Creates a select query
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
options | Select options like |
Creates a query to update a row
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
values | Values to be replaced in the query |
columns | Columns to be selected |
where | Where clause |
Creates a query to delete a row
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
where | Where clause |
Creates a query to check if the table exists
Kind: instance method of Query
Returns:
reference to the instance
Creates a query to check if the column exists
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
name | Name of the column |
type | Data type of the column |
Creates a query to check if the constraint exists
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
name | Name of the constraint |
Creates a query to create a table
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
colsSchema | Schema of the columns |
Creates a query to alter a table to add columns
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
colsSchema | Schema of the columns |
Creates a query to drop a table
Kind: instance method of Query
Returns:
reference to the instance
Creates a query to drop a column
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
name | Name of the column |
Creates a query to add a foreign key constraint
Kind: instance method of Query
Returns:
reference to the instance
Param | Description |
---|---|
options | Options for the constraint |
Runs the query
Kind: instance method of Query
Returns:
reference to the instance
Logs the query and its values
Kind: instance method of Query
Returns:
reference to the instance
Connects to the database
Kind: static method of Query
Param | Description |
---|---|
pgClient | Client object returned by |
Kind: global class
- Table
- new Table(tableName, columns, options)
- instance
- .options
- .name
- .columns
- .query
- .name
- .run(query) ⇒
- .create()
- .select(options) ⇒
- .insert(data) ⇒
- .insertMany(data) ⇒
- .update(data, pkey) ⇒
- .delete(pkey) ⇒
- .exists() ⇒
- .columnExists(name, type) ⇒
- .contraintExists(name) ⇒
- .drop()
- .alter() ⇒
- .addForeignKey(foreignKey)
- .addTimestamps()
- .setParanoid()
- .setColumns(columns)
- .getColumn(colName) ⇒
- .getColumnNames(includeTimestamps) ⇒
- .getValidInputs(allInputs, nulls) ⇒
- .getInputsArrangedAsColumns(allInputs) ⇒
- .runValidations(allInputs)
- static
Creates a new Table
instance
Param | Description |
---|---|
tableName | Name of the table to be created |
columns | Columns to be added to the table |
options | Configuration options for the table |
Gets configurable object
Kind: instance property of Table
Gets the name of the table
Kind: instance property of Table
Gets the columns of the table
Kind: instance property of Table
Gets the query instance
Kind: instance property of Table
Sets the name of the table
Kind: instance property of Table
Runs a query and returns the result
Kind: instance method of Table
Returns:
result of the query
Param | Description |
---|---|
query | Query to be run |
Creates the table in the database
Kind: instance method of Table
Selects data from the table
Kind: instance method of Table
Returns:
selected rows
Param | Description |
---|---|
options | Set options for the query |
Inserts a row into the table
Kind: instance method of Table
Returns:
inserted row
Param | Description |
---|---|
data | Data to be inserted |
Inserts multiple rows into the table
Kind: instance method of Table
Returns:
inserted rows
Param | Description |
---|---|
data | Data to be inserted |
Updates all rows in the table, or a single row if pkey
is provided
Kind: instance method of Table
Returns:
updated row
Param | Description |
---|---|
data | Data to be updated |
pkey | primary key of the row to be updated |
Deletes row(s) from the table
Kind: instance method of Table
Returns:
deleted rows
Param | Type | Description |
---|---|---|
pkey | string | whereOptions |
primary key of the row to be deleted or where options |
Checks if the table exists in the database
Kind: instance method of Table
Returns:
true if the table exists, false otherwise
Checks if the column exists in the table
Kind: instance method of Table
Returns:
true if the column exists, false otherwise
Param | Description |
---|---|
name | Name of the column |
type | Data type of the column |
Check if the constraint exists in the table
Kind: instance method of Table
Returns:
true if constraint exists, false otherwise
Param | Description |
---|---|
name | Name of the table |
Drops the table from database
Kind: instance method of Table
Alters the table in the database
Kind: instance method of Table
Returns:
true if table is altered, false otherwise
Creates a foreign key
Kind: instance method of Table
Param | Description |
---|---|
foreignKey | Object containing foreign key configuration |
Alters table to add timestamps (created_at, updated_at) columns in it
Kind: instance method of Table
Adds deleted_at column in the table
Kind: instance method of Table
Sets new columns on table instance
Kind: instance method of Table
Param | Description |
---|---|
columns | Object containing table columns configuration |
Gets column object
Kind: instance method of Table
Returns:
matched column
Param | Description |
---|---|
colName | Column name |
Get array of column names
Kind: instance method of Table
Returns:
array of column names
Param | Default | Description |
---|---|---|
includeTimestamps | false |
true for including timestamp columns names, false otherwise |
Returns a list of valid inputs
Kind: instance method of Table
Returns:
object of valid inputs, columnName-input pairs
Param | Default | Description |
---|---|---|
allInputs | User inputs object |
|
nulls | false |
If true, will return nulls for missing inputs |
Arranges keys in input object according to arrangment of columns object
Kind: instance method of Table
Returns:
object of arranged inputs
Param | Description |
---|---|
allInputs | object containing user inputs |
Runs validation functions of all columns on corresponding input value
Kind: instance method of Table
Param | Description |
---|---|
allInputs | object containing user inputs |
Connects to the database
Kind: static method of Table
Param | Description |
---|---|
client | Client to be used for the query (to connect to the database) |