Options
All
  • Public
  • Public/Protected
  • All
Menu
     

Class SQL

Hierarchy

  • SQL

Index

Constructors

constructor

  • new SQL(): SQL
  • A collection of SQL Utilities

    Returns SQL

Methods

Static QRY

  • QRY(instatiate?: boolean): QRY
  • Instantiates a new QRY object, unless otherwise specified

    Parameters

    • Optional instatiate: boolean

      if false, does NOT instatiate the QRY

    Returns QRY

    An instatiated QRY object, unless otherwise specified

Static SLC

  • SLC(...columns?: string | object): QRY
  • Begin a SELECT statement

    Parameters

    • Optional Rest ...columns: string | object

      The columns to SELECT

    Returns QRY

    The QRY instance chain

Static INS

  • INS(table: string, ...columns: string): QRY
  • Begin a INSERT statement

    Parameters

    • table: string

      The table recieving INSERTS

    • Rest ...columns: string

      The columns recieving VALUES

    Returns QRY

    The QRY instance chain

Static UPD

  • UPD(table: string, ...options: string): QRY
  • Begin a UPDATE statement

    Parameters

    • table: string

      The table recieving UPDATES

    • Rest ...options: string

      An optional identifer and database for the table

    Returns QRY

    The QRY instance chain

Static DEL

  • Begin a DELETE statement

    Returns QRY

    The QRY instance chain

Static PLACEHOLD

  • PLACEHOLD(key: string): RegExp
  • Creates a regex pattern to match a query-template placeholder

    Parameters

    • key: string

      The placeholder's name

    Returns RegExp

    The regex pattern

Static FORMAT

  • FORMAT(query: string, values: object): string
  • Takes a query-template and replaces the placeholders with the values specified

    Parameters

    • query: string

      An SQL query-template. This utilizes :NAME: placeholders

    • values: object

      The values to place into the query

      • [key: string]: string | number

    Returns string

    The formatted SQL query

Static CLAUSE

  • CLAUSE(column: string, operator: string, condition: string, prefix: string): string
  • Formats a clause for use in a SQL query

    Parameters

    • column: string

      The column-name this clause pertains to

    • operator: string

      The comparison operator (=|IN|EXISTS|REGEXP|...)

    • condition: string

      The value the column should conform to

    • prefix: string

      The type of clause (WHERE|AND|OR)

    Returns string

    The formatted SQL clause

Static TYPE

  • TYPE(field: mysql.Field, next: mysql.parser): mysql.parser
  • A default type-parser for SQL result columns

    Parameters

    • field: mysql.Field

      A MySQL.Field object

    • next: mysql.parser

      The next Field

    Returns mysql.parser

    The next field's parser

Static PAGE

  • PAGE(vals: Object, threshold: Object): Object
  • Restricts a pagination object to positive numbers and any specified thresholds

    Parameters

    • vals: Object

      A pagination object, specifying a page number & result limit

    • threshold: Object

      The page & number restrictions for the object

    Returns Object

    The restricted pagination object

Static JOIN

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

    Parameters

    • 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

    • Optional filter: TFilter

      A TFilter that will trickle down to the matching index of the coalesce/converter

    • Optional coalesce: TCoalesce

      A TCoalesce objects that will trickle down to the matching index of the converter

    • Optional convert: CBConvert

      A CBConvert to handle custom transformations matching the index of the corresponding filter object.

    Returns string

    The transformed query-clause

Static LIST

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

    Parameters

    • vals: string | string[]

      Either a string or array of strings to include in the clause. Each subsequent filter/coalesce/converter will be applied to each string

    • Optional filters: TFilter | TFilter[]

      An array of TFilters that will trickle down to the matching index of the coalesce/converters

    • Optional coalesces: TCoalesce | TCoalesce[]

      An array of TCoalesces objects that will trickle down to the matching index of the converters

    • Optional converters: CBConvert | CBConvert[]

      An array of CBConverts to handle custom transformations matching the index of the corresponding filter object.

    Returns string[]

    The transformed Array of query-clauses

Static BRKT

  • BRKT(val: string[], brackets: string[], join: string): string
  • Concatenates an Array of values, separated by a specified string, and finally, wrapped in specified brackets

    Parameters

    • val: string[]

      An array of values to wrap in brackets

    • brackets: string[]

      An array (length<=2) specifiying the opening and closing brackets

    • join: string

      The string to separate the concatenations

    Returns string

    The formatted expression

Static COALESCE

  • COALESCE(): string
  • Not implemented yet.

    Returns string

Static CONCAT

  • CONCAT(...args: string | number): string
  • Creates an CONCAT expression for use in a SQL query

    Parameters

    • Rest ...args: string | number

      The strings to concatenate

    Returns string

    The formatted expression

Static CONCAT_WS

  • CONCAT_WS(separator: string, ...args: string | number): string
  • Creates an CONCAT_WS expression for use in a SQL query

    Parameters

    • separator: string

      The string to separate the concatenations

    • Rest ...args: string | number

      The strings to concatenate

    Returns string

    The formatted expression

Static SOCKET

  • SOCKET(options?: Object): string
  • Allows you to create SocketLinks in a SQL query

    Parameters

    • Optional options: Object

    Returns string

    A column SELECT statement that formats SocketLink string within a SQL query

Static LIMIT

  • LIMIT(limit: number): string
  • Creates an LIMIT clause for use in a SQL query

    Parameters

    • limit: number

      The limit value

    Returns string

    The formatted clause

Static OFFSET

  • OFFSET(offset: number): string
  • Creates an OFFSET clause for use in a SQL query

    Parameters

    • offset: number

      The offset value

    Returns string

    The formatted clause