• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Thin and less-opinionated database abstraction layer for node.

Any-DB

Build Status

The less-opinionated Node.js database abstraction layer

Status

Any-DB is in maintenance mode and bug fixes will happen infrequently/never.* What this means for you depends on how you are using any-db:

  • If you need support for a fixed set of database engines: you should replace the dependency on any-db with the underlying database driver(s). Code adjustments should be minimal and you'll get access to all the modern features provided by the database drivers that any-db doesn't expose (such as promises).
  • If you need to support arbitrary runtime defined database connections: any-db is still functional, but has had to start restricting the driver versions it depends on. If you are interested in maintaining these packages feel free to contact me.
  • If you are using a library that depends on any-db: contact the author of that library and ask them to read this notice.

* Why? I haven't used any-db myself in nearly a decade and there are no other maintainers.

Synopsis

Establish a connection:

// Takes an optional callback
var conn = anyDB.createConnection('driver://user:pass@hostname/database')

Make queries:

var sql = 'SELECT * FROM questions'

// query() returns a readable stream
conn.query(sql).on('data', function (row) {})

// pass a callback to collect results
conn.query(sql, function (error, result) {})

Use bound parameters:

sql += ' WHERE answer = ?'
conn.query(sql, [42], function (err, res) {})

Manage database transactions with any-db-transaction:

var begin = require('any-db-transaction')

var tx = begin(conn)              // Can also take a callback
tx.on('error', function (err) {}) // Emitted for unhandled query errors
tx.query(...)                     // same interface as connections, plus...
tx.rollback()                     // this too
tx.commit()                       // takes an optional callback for errors

Create a connection pool that maintains 2-20 connections:

var pool = anyDB.createPool(dbURL, {min: 2, max: 20})

pool.query(...)       // perform a single query, same API as connection
var tx = begin(pool)  // create a transaction with the first available connection
pool.close()          // close the pool (call when your app should exit)

Description

The purpose of this library is to provide a consistent API for the commonly used functionality of SQL database drivers, while avoiding altering driver behaviour as much as possible.

Installation

For Applications

npm install --save any-db-{postgres,mysql,sqlite3,mssql} any-db

All of the adapter libraries have any-db as a peerDependency, which means that you will have to install any-db as well.

For Libraries

Add any-db to peerDependencies in package.json. This allows users of your library to satisfy the any-db dependency by installing the adapter of their choice. If you need to run tests, list it as a devDependency too.

API

module.exports := {
  createConnection: (Url, Continuation<Connection>?) => Connection
  createPool: (Url, PoolConfig) => ConnectionPool
}

Url := String | { adapter: String }

PoolConfig := {
  min: Number,
  max: Number,
  onConnect: (Connection, ((Error) => void) => void
  reset: (Connection, ((Error) => void) => void
}

Continuation := (Maybe<Error>, Any) => void

The API of Connection and Query objects is fully described in the adapter-spec, while Transaction and ConnectionPool objects have their own documentation. Connections, transactions and pools all have a query method that behaves consistently between drivers.

Both exported functions require an Url as their first parameter. This can either be a string of the form adapter://user:password@host/database (which will be parsed by parse-db-url) or an object. When an object is used, it must have an adapter property, and any other properties required by the specified adapters createConnection method.

See also: README for your chosen adapter (MS SQL, MySQL, Postgres, and SQLite3)

License

MIT

More Repositories

1

merge-stream

Merge multiple streams into one interleaved stream
JavaScript
212
star
2

js-shell-parse

parse bash, with javascript (UNMAINTAINED)
JavaScript
88
star
3

ts-react-loader

Automatic prop-types from TypeScript types
TypeScript
70
star
4

uri-template

TypeScript/Javascript implementation of RFC 6570 for URI-templates
TypeScript
42
star
5

js-capitalize

capitalize a string, or all words in a string
JavaScript
37
star
6

guacamole-auth-hmac

UNMAINTAINED! Create Guacamole configurations via (signed) URL query parameters
Java
18
star
7

npm-exec

UNMAINTAINED! npm run-script for arbitrary commands
JavaScript
11
star
8

node-any-db-pool

Connection pool used by any-db
JavaScript
8
star
9

node-any-db-transaction

JavaScript
8
star
10

otssh

One-time SSH daemon
Go
7
star
11

browserify-as-a-service

Prototype for creating browserified bundles on demand.
JavaScript
7
star
12

web-pockets

JavaScript
7
star
13

js-pockets

JavaScript
6
star
14

node-any-db-postgres

JavaScript
6
star
15

js-shell-frontend

Frontend for a posix shell, written in JavaScript
JavaScript
6
star
16

react-async-input

Inputs that behave properly with async set{State,Props} calls
JavaScript
5
star
17

parse-db-url

JavaScript
5
star
18

refify

Safe, cross-language JSON encoding/decoding of structures containing circular references
JavaScript
4
star
19

mmr

Add reminders for yourself in directories
Rust
4
star
20

xstate

Ruby port of https://github.com/davidkpiano/xstate
Ruby
4
star
21

node-any-db-adapter-spec

Specification and test suite for any-db database adapters
JavaScript
4
star
22

php-guacamole-url-builder

Create signed URLs for use with guacamole-auth-hmac in PHP.
PHP
4
star
23

pct-encode

Standards compliant percent-encoding
JavaScript
4
star
24

js-is-function

JavaScript
3
star
25

codd

Golang representation of relational algebra
Go
3
star
26

markdown-code-blocks

JavaScript
3
star
27

node-any-db-mysql

MySQL adapter for any-db
JavaScript
3
star
28

eav

Go
3
star
29

api-console

Elm
2
star
30

yafsm

Yet-another-finite-state-machine
JavaScript
2
star
31

js-compose-promise

JavaScript
2
star
32

guacamole-server-debian

Packaging scripts for building guacamole-server from source on debian
Shell
2
star
33

rtorrent-client

cross-platform, wxPython based rtorrent xmlrpc client that attempts to minimize network usage
Python
2
star
34

chocolate-rain

A Cocoa based rTorrent front end
Objective-C
2
star
35

semver-intersection

JavaScript
2
star
36

js-prat

promise aware transform streams
JavaScript
1
star
37

prepend-listener

JavaScript
1
star
38

dev-mode

JavaScript
1
star
39

awesome-configs

Awesome configuration
Lua
1
star
40

code_garden

An interactive source code visualizer
1
star
41

moose

orm to work with nodejs
JavaScript
1
star
42

autotagfs

A python FUSE module that automatically tags media files based on their path
Python
1
star
43

js-create-class

JavaScript
1
star
44

js-doto

A JavaScript version of Clojure's 'doto macro
JavaScript
1
star
45

library

Library system - SDO project
Ruby
1
star
46

dyno

Dynamic tagging module for the awesome wm
Lua
1
star
47

drone-kubernetes

Shell
1
star
48

js-fast-getter

JavaScript
1
star
49

json.pony

Simple JSON parser for Ponylang
1
star
50

create-dependency-stream

Creates a stream of dependency objects from a parsed package.json file.
JavaScript
1
star
51

node-any-db-sqlite3

JavaScript
1
star
52

node-argv2http

Easily create declarative CLI wrappers for HTTP API's
JavaScript
1
star
53

vdom-rs

Rust
1
star
54

js-pure-objects

JavaScript
1
star
55

Pass-StatusBar

A status bar password manager using GPG2 encrypted files.
Ruby
1
star
56

foreign-state

Attach hidden state to arbitrary objects in JavaScript (like jQuery.data() without the jQuery)
JavaScript
1
star
57

node-sqlite3-reflect

Database reflection for sqlite3
JavaScript
1
star
58

js-set-object-path

JavaScript
1
star
59

coffee-sphinx

Coffee Script domain and autodoc support for Sphinx
Python
1
star