Build a SQL connector

Use the loopback-connector module to build a LoopBack connector to back-end data sources such as databases or web services. There are many existing connectors for the most popular data sources; see:

To build a new data source connector that doesn't yet exist, please see Building a connector for a relational database.

Base Connector

SQL Connector

ParameterizedSQL(sql, params)

A class for parameterized SQL clauses

Arguments
Name Type Description
sql String or Object

The SQL clause. If the value is a string, treat it as the template using ? as the placeholder, for example, (?,?). If the value is an object, treat it as {sql: '...', params: [...]}

params Array.<*>

An array of parameter values. The length should match the number of placeholders in the template

Returns
Name Type Description
result ParameterizedSQL

A new instance of ParameterizedSQL

parameterizedSQL.merge(ps, [separator])

Merge the parameterized sqls into the current instance

Arguments
Name Type Description
ps Object or Array.<Object>

A parametered SQL or an array of parameterized SQLs

[separator] String

Separator, default to

Returns
Name Type Description
result ParameterizedSQL

The current instance

ParameterizedSQL.append(currentStmt, stmt, [separator])

Append the statement into the current statement

Arguments
Name Type Description
currentStmt Object

The current SQL statement

stmt Object

The statement to be appended

[separator] String

Separator, default to

Returns
Name Type Description
result

The merged statement

ParameterizedSQL.join(sqls, [separator])

Join multiple parameterized SQLs into one

Arguments
Name Type Description
sqls Array.<Object>

An array of parameterized SQLs

[separator] String

Separator, default to

Returns
Name Type Description
result ParameterizedSQL