1.1.0 • Published 10 years ago

common-storage-sql v1.1.0

Weekly downloads
9
License
-
Repository
github
Last release
10 years ago

Common Storage SQL

An abstract SQL driver for Common Storage, part of the Common Framework. It uses squel to build queries.

Installation

Install it from NPM:

npm install common-storage-sql

Usage

Database

The abstract Database class manages tables and serializes Squel queries for consumption by an implementing class. It has the following methods:

  • fetchTable(key) returns the cached table with that key or acquires it
  • fetchTables(keys)
  • acquireTable(key) makes a new table instance
  • query(query) takes a Squel query or string and executes it

Classes that extend Database should implement the _query(query) method, which takes and executes a string and returns a result identical in behavior to those returned by node-postgres.

Table

The Table class extends and implements the abstract methods from the Storage class. Additionally, it has the following methods:

  • referenceBy(property) defines the column in the table representing the key, which is by default just "key"
  • query takes a Squel query, localizes it to the table, and then executes it
  • querySelectAll(query) asynchronously returns an array of objects of rows matching a selection
  • querySelectSingle(query) asynchronously returns a single row matching a single