Connections
Connection types:
- Knex
Knex
Properties
client: enum
: Required - Use themysql
client to connect to MariaDB.connection: object | string
: Required - Connection object or string to pass to themysql
database client.version: string
: Set database version.useNullAsDefault: boolean
: If true, undefined keys are replaced with NULL instead of DEFAULT.
Examples
Connection object:
connections:
- id: mariadb
type: Knex
properties:
client: mysql
connection:
host:
_secret: MARIADB_HOST
database:
_secret: MARIADB_DB
user:
_secret: MARIADB_USER
password:
_secret: MARIADB_PASSWORD
Environment variables:
LOWDEFY_SECRET_MARIADB_HOST = database.server.com
LOWDEFY_SECRET_MARIADB_DB = db
LOWDEFY_SECRET_MARIADB_USER = user
LOWDEFY_SECRET_MARIADB_PASSWORD = password
Requests
Request types:
- KnexBuilder
- KnexRaw
KnexBuilder
Properties
query: object[]
: Required - SQL query builder array. An array of objects, with a single key which is the name of the knex builder function. The value should be an array of arguments to pass to the builder function.tableName: string | object
: The name of the table to query from.
Examples
Build a query:
id: knexBuilder
type: KnexBuilder
connectionId: knex
properties:
query:
- select:
- '*'
- from:
- users
- where:
- name
- _state: name
Using tableName
:
id: knexBuilder
type: KnexBuilder
connectionId: knex
properties:
tableName: users
query:
- select:
- '*'
- where:
- name
- _state: name
Aliases:
id: knexBuilder
type: KnexBuilder
connectionId: knex
properties:
tableName:
a: tableA
b: tableB
query:
- select:
- aField: 'a.field'
- bField: 'b.field'
- limit:
- 1
KnexRaw
Properties
query: string
: Required - SQL query string.parameters: string | number | array | object
: SQL query parameters.
Examples
Simple raw query:
id: knexRaw
type: KnexRaw
connectionId: knex
properties:
query: SELECT * FROM "my_table";
Query with named parameters:
id: knexRaw
type: KnexRaw
connectionId: knex
properties:
query: select * from users where name = :name
parameters:
name:
_state: selected_name
Query with positional parameters:
id: knexRaw
type: KnexRaw
connectionId: knex
properties:
query: select * from users where name = ?
parameters:
- _state: selected_name
Reference a .sql
file:
id: knexRaw
type: KnexRaw
connectionId: knex
properties:
query:
_ref: my_query.sql