1.1.0 • Published 8 years ago
common-storage-sql v1.1.0
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 itfetchTables(keys)
acquireTable(key)
makes a new table instancequery(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 itquerySelectAll(query)
asynchronously returns an array of objects of rows matching a selectionquerySelectSingle(query)
asynchronously returns a single row matching a single