Skip to content

Latest commit

 

History

History
114 lines (84 loc) · 4.3 KB

api.md

File metadata and controls

114 lines (84 loc) · 4.3 KB

Functions

getSql(query, opt)string

Get full sql statement.

limit(page, size)String

Get limit clause of a query.

getCount(countResult)Number

Get count number of a count query.

getWhere(where)String

Get where clause of a query.

toDatetimeStr(date)String

Generate a valid datetime string for mysql.

snakeToCamel(data, depth)Object | String

Convert format of keys of an object from snake-case to camel-case.

camelToSnake(data, depth)Object | String

Convert format of keys of an object from camel-case to snake-case.

getSql(query, opt) ⇒ string

Get full sql statement.

Kind: global function
Returns: string - sql string

Param Type Description
query Object A JSON object which supports three types of key: table(required), where, limit, orderBy e.g. { table: 'table_name', where: {}, limit: [], orderBy: [] }
opt Object setting of query: count, distinct, fields (only one can be set) e.g. { distincts: ['id', 'type'], count: false, fields: ['id', 'type'] }

limit(page, size) ⇒ String

Get limit clause of a query.

Kind: global function
Returns: String - sql clause for 'SQL-Limit'

Param Type Description
page Number number
size Number number of items in a page

getCount(countResult) ⇒ Number

Get count number of a count query.

Kind: global function
Returns: Number - count number

Param Type Description
countResult QueryResult a result of executing a count query.

getWhere(where) ⇒ String

Get where clause of a query.

Kind: global function
Returns: String - sql clause for 'SQL-Where'

Param Type Description
where Object conditions A JSON object which supports three types of key: 1. field_name, 2. $and, 3. $or Supported logical oprator: $eq / ===, $neq / !==, $gt(e) / >(=), $lt(e) / <(=), $like, $in e.g. conditions = { key1: 1, key2: { $or: { $neq: 1, $in: [2, 3, 4] } }, key3: { $like: 'test' } }

toDatetimeStr(date) ⇒ String

Generate a valid datetime string for mysql.

Kind: global function
Returns: String - formated datetime string

Param Type Description
date DateTime | Date | String datetime in mysql or date in js

snakeToCamel(data, depth) ⇒ Object | String

Convert format of keys of an object from snake-case to camel-case.

Kind: global function
Returns: Object | String - string or keys of object are named in form of camel case

Param Type Description
data Object | String string or keys of object are named in form of snake
depth Number to which level of keys should it process

camelToSnake(data, depth) ⇒ Object | String

Convert format of keys of an object from camel-case to snake-case.

Kind: global function
Returns: Object | String - string or keys of object are named in form of snake

Param Type Description
data Object | String string or keys of object are named in form of camel case
depth Number to which level of keys should it process