postgres-repo
A light, promise-based alternative to a full ORM that simply wraps a repository pattern around basic PostgreSQL calls.
Installation
$ npm install postgres-repo
Usage
Create a new repo by providing the database connection URL and a table name.
This will use the built-in connection pools setup on the global pg
object.
var PostgresRepo = require('postgres-repo');
var users = new PostgresRepo(DATABASE_URL, 'user');
You can also specify a different primary key (default is simply id
);
var users = client 'users' 'user_id';
Get a row from the table by its primary key
users;
Get an array of all of the items in the table
users;
Add a new row to the table. The returned representation will be what is stored,
including any default values set during the INSERT
command.
var user = email: 'billy@awesome.net' name: 'Billy' ;users;
Remove a row that correlates to some object representation. This checks the
identity primary key (e.g, id
) to execute the DELETE
command.
users;
Update a row that correlates to some object representation. This checks the
identity primary key and executes an UPDATE
command.
username = 'Bob';users;
Execute a query with parametric values (automatically escaped appropriately by
the underlying pg
driver)
users ;
Testing
$ npm test
License
MIT