Sails MariaDB
MariaDB service for sails.js server
Install
npm i sails-mariadb
Usage
config/connection.js
moduleexportsconnections = //... MariaDBInfo: host: 'localhost' user: 'root' password: 'pw' database: 'db' multipleStatements: true connectionLimit: 10 //...
or sails.config.MariaDBInfo(higher priority)
This module is based on node mysql. same configuration
In sails controller
const MariaDB =
This function is based on co. same usage.
In generator function, all queries are in transaction.
And will auto commit transaction if all promises are resolved in function
and auto rollback if there's any promise rejection in function.(only promises with yield)
query result is same as mysql
Connection Object Structure
└── conn
├── beginTransaction : Promise
├── changeUser : Promise
├── commit : Promise
├── destroy
├── on : Promise
├── ping : Promise
├── query : Promise
├── release
├── rollback : Promise
├── prototype : PoolConnection (original connection from mysql module)
└── (prototype) : PoolConnection (original connection from mysql module)
NOTE: If want to call that not own method of this object,
please use 'conn.prototype.foo(...args)'
Query Statement
conn.query(sql, params)
In sql
string
:variableName
- same as?
in node mysql. target value isparams.variableName
.;variableName
- same as??
in node mysql. target value isparams.variableName
.$variableName
- replace$variableName
asparams.variableName
with escaped string in sql string.#variableName
- replace#variableName
asparams.variableName
with raw string in sql string. (unsafe!)
Config
const config = useStream: // default : false { // handle fields (if exist) } { // handle a row }
Global Config
const MariaDB = MairaDBconfiguseStream = /* ... */
Instance Config
const MariaDB =
License
The MIT License (MIT)
Copyright (c) 2017 Elevista