Skip to content
Arian Johnson edited this page May 4, 2018 · 22 revisions

A collection of SQL Utilities

Kind: global class


Callers

SQL.QRY(instatiateopt)QRY

Instantiates a new QRY object, unless otherwise specified

  • Kind: static method of SQL
  • Returns: QRY - An instatiated QRY object, unless otherwise specified
Param Type Default Description
instatiate opt boolean true if false, does NOT instatiate the QRY

SQL.SLC(...columnsopt)QRY

Begin a SELECT statement

  • Kind: static method of SQL
  • Returns: QRY - The QRY instance chain
Param Type Description
...columns opt string | Object.<string, string> The columns toSELECT

SQL.INS(table, ...columns)QRY

Begin a INSERT statement

  • Kind: static method of SQL
  • Returns: QRY - The QRY instance chain
Param Type Description
table string The table recieving INSERTS
...columns string The columns recieving VALUES

SQL.UPD(table, ...options)QRY

Begin a UPDATE statement

  • Kind: static method of SQL
  • Returns: QRY - The QRY instance chain
Param Type Description
table string The table recieving UPDATES
...options string An optional identifer and database for the table

SQL.DEL()QRY

Begin a DELETE statement

  • Kind: static method of SQL
  • Returns: QRY - The QRY instance chain

Statics

SQL.PLACEHOLD(key)RegExp

Creates a regex pattern to match a query-template placeholder

  • Kind: static method of SQL
  • Returns: RegExp - The regex pattern
Param Type Description
key string The placeholder's name

SQL.FORMAT(query, values)string

Takes a query-template and replaces the placeholders with the values specified

  • Kind: static method of SQL
  • Returns: string - The formatted SQL query
Param Type Description
query string An SQL query-template. This utilizes :NAME: placeholders
values Object.<string, (string|number)> The values to place into the query

SQL.CLAUSE(column, operator, condition, prefix)string

Formats a clause for use in a SQL query

  • Kind: static method of SQL
  • Returns: string - The formatted SQL clause
Param Type Description
column string The column-name this clause pertains to
operator string The comparison operator (=
condition string The value the column should conform to
prefix string The type of clause (WHERE

SQL.TYPE(field, next)mysql.parser

A default type-parser for SQL result columns

  • Kind: static method of SQL
  • Returns: mysql.parser - The next field's parser
Param Type Description
field mysql.Field A MySQL.Field object
next mysql.parser The next Field

SQL.PAGE(vals, threshold)Object

Restricts a pagination object to positive numbers and any specified thresholds

  • Kind: static method of SQL
  • Returns: Object - The restricted pagination object
Param Type Description
vals Object A pagination object, specifying a page number & result limit
threshold Object The page & number restrictions for the object

SQL.JOIN(vals, filteropt, coalesceopt, convertopt)string

A reducer, which filters, coalesces, converts (transforms), and joins delimited string to build a complex query-clause

  • Kind: static method of SQL
  • Returns: string - The transformed query-clause
Param Type Description
vals string Either a string or array of strings to include in the clause. Each subsequent filter/coalesce/converter will be applied to each string
filter opt TFilter A TFilter that will trickle down to the matching index of the coalesce/converter
coalesce opt TCoalesce A TCoalesce objects that will trickle down to the matching index of the converter
convert opt CBConvert A CBConvert to handle custom transformationsmatching the index of the corresponding filter object.

SQL.LIST(vals, filtersopt, coalescesopt, convertersopt)Array<string>

A reducer, which filters, coalesces, converts (transforms), and joins a list of delimited string tobuild a complex Array of query-clauses

  • Kind: static method of SQL
  • Returns: Array<string> - The transformed Array of query-clauses
Param Type Description
vals string | Array<string> Either a string or array of strings to include in the clause. Each subsequent filter/coalesce/converter will be applied to each string
filters opt TFilter | Array<TFilter> An array of TFilters that will trickle down to the matching index of the coalesce/converters
coalesces opt TCoalesce | Array<TCoalesce> An array of TCoalesces objects that will trickle down to the matching index of the converters
converters opt CBConvert | Array<CBConvert> An array of CBConverts to handle custom transformations matching the index of the corresponding filter object.

SQL.BRKT(val, brackets, join)string

Concatenates an Array of values, separated by a specified string, and finally, wrapped in specifiedbrackets

  • Kind: static method of SQL
  • Returns: string - The formatted expression
Param Type Description
val Array<string> An array of values to wrap in brackets
brackets Array<string> An array (length<=2) specifiying the opening and closing brackets
join string The string to separate the concatenations

SQL.COALESCE()string

Not implemented yet.

  • Kind: static method of SQL

SQL.CONCAT(...args)string

Creates an CONCAT expression for use in a SQL query

  • Kind: static method of SQL
  • Returns: string - The formatted expression
Param Type Description
...args string | number The strings to concatenate

SQL.CONCAT_WS(separator, ...args)string

Creates an CONCAT_WS expression for use in a SQL query

  • Kind: static method of SQL
  • Returns: string - The formatted expression
Param Type Description
separator string The string to separate the concatenations
...args string | number The strings to concatenate

SQL.SOCKET(optionsopt)string

Allows you to create SocketLinks in a SQL query

  • Kind: static method of SQL
  • Returns: string - A column SELECT statement that formats SocketLink string within a SQL query
Param Type Default
options opt Object {link:"",columns:null,escapes:1}

SQL.LIMIT(limit)string

Creates an LIMIT clause for use in a SQL query

  • Kind: static method of SQL
  • Returns: string - The formatted clause
Param Type Description
limit number The limit value

SQL.OFFSET(offset)string

Creates an OFFSET clause for use in a SQL query

  • Kind: static method of SQL
  • Returns: string - The formatted clause
Param Type Description
** offset** number The offset value