sql

Methods

(static) column(req, name)

Description:
  • Return properly quoted column name if it is a keyword

Parameters:
Name Type Description
req DBRequest

current request

name string

column name

(static) create(req)

Description:
  • Create SQL table using table definition

Parameters:
Name Type Description
req DBRequest

request object

(static) delete(req)

Description:
  • Build SQL statement for delete

Parameters:
Name Type Description
req DBRequest

request object

(static) drop(req)

Description:
  • Create SQL DROP TABLE statement

Parameters:
Name Type Description
req DBRequest

request object

(static) expr(req, name, value, optionsopt)

Description:
  • Build SQL expressions for the column and value

Parameters:
Name Type Attributes Description
req DBRequest

current request

name string

column name

value any

value to compare

options DBRequestColumn <optional>

column definition returned by module.db:prepareColumn

(static) get(req)

Description:
  • Get one record from the database

Parameters:
Name Type Description
req DBRequest

request object

Properties
Name Type Attributes Description
options.select Array.<string> <optional>

is a list of columns or expressions to return

(static) insert(req)

Description:
  • Build SQL insert statement

Parameters:
Name Type Description
req DBRequest

request object

(static) limit(req)

Description:
  • Build SQL orderby/limit/offset conditions, config can define defaults for sorting and paging

Parameters:
Name Type Description
req DBRequest

current request

(static) quote()

Description:
  • Quote value to be used in SQL expressions

(static) select(req)

Description:
  • Select object from the database

Parameters:
Name Type Description
req DBRequest

request object

Properties
Name Type Attributes Description
options.select Array.<string> <optional>

is list of columns or expressions to return

(static) time()

Description:
  • Return time formatted for SQL usage as ISO, if no date specified returns current time

(static) update(req)

Description:
  • Build SQL statement for update

Parameters:
Name Type Description
req DBRequest

request object

(static) upgrade(req)

Description:
  • Create ALTER TABLE ADD COLUMN statements for missing columns

Parameters:
Name Type Description
req DBRequest

request object

(static) value(value, optionsopt)

Description:
  • Return properly quoted value to be used directly in SQL expressions, format according to the type

Parameters:
Name Type Attributes Description
value any

column value to format

options DBRequestColumn <optional>

(static) valueIn()

Description:
  • Return list in format to be used with SQL IN ()

(static) where(req, query, joinopt)

Description:
  • Build SQL where condition from the keys and object values, returns SQL statement to be used in WHERE

Parameters:
Name Type Attributes Description
req DBRequest

current request

query object

properties for the condition, in case of an array the primary keys for IN condition will be used only, a property named or$ or and$ will be treated as a sub-expression if it is an object. Add a number if need multiple OR/AND conditions like or$$, or$$,...

join string <optional>

AND is default