Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

object-layer/anysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AnySQL Build Status

Modern minimal API for any SQL database.

Features

  • Unified API for several database engines.
  • No need to manage connections, just query the database.
  • Easy transactions with automatic begin/commit/rollback.
  • Asynchronous functions return promises, feel free to handle them with ES7 async/await feature.

Supported databases

Installation

npm install --save anysql

Usage

Simple query

import AnySQL from 'anysql';

let anysql = new AnySQL('mysql://test@localhost/test');
let rows = await anysql.query('SELECT ? + ? AS solution', [2, 3]);
console.log(rows[0].solution); // => 5

Transactions

import AnySQL from 'anysql';

let anysql = new AnySQL('mysql://test@localhost/test');
await anysql.transaction(async function(transaction) {
  let rows = await transaction.query('SELECT ...');
  // ...
  await transaction.query('UPDATE ...');
  // ...
  // if no error has been thrown, the transaction is automatically committed
});

License

MIT

About

Modern minimal API for any SQL database

Resources

Stars

Watchers

Forks

Packages

No packages published