npm

Need private packages and team management tools?Check out npm Orgs. »

This package has been deprecated

Author message:

No longer maintained

mariasql-promise

2.0.0 • Public • Published

MariaSQL-Promise

A lightweight Promise wrapper for MariaSQL that also works with MySQL. To see the list of available options, please have a look at MariaSQL's README.

Installation

npm install mariasql-promise

Usage

import MariaSQL from 'mariasql-promise'
 
const db = new MariaSQL()
db.connect({
  host: '127.0.0.1',
  user: 'test',
  password: 'test',
  db: 'test'
}).then(function() {
  console.log('connected')
 
  const selectQuery = db.query('Select 1 + 1 as result')
    .then(function(rows) {
      console.log('result was', rows[0].result)
    })
  const escapedQuery = db.query('Select * from users where id = ? LIMIT 1', [1])
    .then(function(rows) {
      console.log('the user was', rows.length ? 'found' : 'not found')
    })
  const parameterizedQuery = db.query('Select * from users where id = :id and name = :name LIMIT 1', [1, 'steel'])
    .then(function(rows) {
      console.log('steel was', rows.length ? 'found' : 'not found')
    })
  const preparedQuery = db.query(db.prepare('Select COUNT(users) as count from users as a where EXISTS(Select 1 from users where user.name = a.name AND user.id != a.id)'))
    .then(function(rows) {
      console.log('number of users with same name is', rows[0].count)
    })
 
  return Promise.all([selectQuery, escapedQuery, parameterizedQuery, preparedQuery])
}).catch(function(e) {
  console.log('We have a problem', e.message, e.stack)
})

API

export class MariaDB {
  connect(config): Promise
  query(query, params = null): Promise<Array<Object>>
  prepare(query: String)
  terminate()
  dispose()
}

License

This project is licensed under the terms of MIT License. See the LICENSE file for more info.

install

npm i mariasql-promise

Downloadsweekly downloads

20

version

2.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability