sails-mariadb
MariaDB service for sails.js server
Last updated a month ago by elevista .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install sails-mariadb 
SYNC missed versions from official npm registry.

Sails MariaDB

MariaDB service for sails.js server

npm package JavaScript Style Guide

Install

npm i sails-mariadb

Usage

config/connection.js

module.exports.connections = {
  //...
  MariaDBInfo: {
    host: 'localhost',
    user: 'root',
    password: 'pw',
    database: 'db',
    multipleStatements: true,
    connectionLimit: 10
  },
  //...
}

or sails.config.MariaDBInfo(higher priority)

node mysql was used.
same configuration

In sails controller

const MariaDB = require('sails-mariadb')
MariaDB(function * (conn) {
  let rows = yield conn.query(`SELECT * FROM table WHERE id=:id`, {id: 10})
  let res = yield conn.query(`INSERT INTO table2 SET foo=:foo`, {foo: 'foo'})
  return {rows, affectedRows: res.affectedRows}
}).then(r => console.log(r), e => console.error(e))

co was used. same usage.

conn.query returns promise.
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

Query Statement

conn.query(sql, params)
In sql string

  • :variableName - same as ? in node mysql. target value is params.variableName.
  • ;variableName - same as ?? in node mysql. target value is params.variableName.
  • $variableName - replace $variableName as params.variableName with escaped string in sql string.
  • #variableName - replace #variableName as params.variableName with raw string in sql string. (unsafe!)

License

The MIT License (MIT)
Copyright (c) 2017 Elevista

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 35
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |