1.0.2 • Published 9 years ago

acidjs v1.0.2

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

acid.js

A simple postgres library

Built on top of pg and psqljs

Build Status

Install

$ npm install --save acidjs

Examples

// Require the module
var acid = require("acidjs")("postgres://postgres:@localhost:5432/database");

Create a table

$ psql -c "create table users (id bigserial primary key, email text not null, created_at timestamp without time zone default (now() at time zone "utc"));"

Insert a record

var tables = {
  users: "users"
};

acid
.insert(tables.users, {email: "test@example.com"});
.then(function(rows) {
  /*
    rows === [
      {
        id: "1",
        email: "test@example.com",
        created_at: ...
      }
    ]
  */
});

Find a record with a where clause

acid
.where(tables.users, "id = $1", "1")
.then(function(rows) {
  /*
    rows === [
      {
        id: "1",
        email: "test@example.com",
        created_at: ...
      }
    ]
  */
});

Update a record

acid
.update(tables.users, {name: "Ryan Dahl"}, "id = $1", "1")
.then(function(rows) {
  /*
    rows === [
      {
        id: "1",
        name: "Ryan Dahl",
        created_at: ...
      }
    ]
  */
})

Delete a record

acid
.delete(tables.users, "id = $1", "1")
.then(function(rows) {
  // rows == []
});

Run arbitrary sql

acid
.sql("select * from user_defined_function($1)", ["value"])
.then(function(rows) {
  /*
    rows === [
      {
        ... whatever data
      }
    ]
  */
})

Tests

# Set up the database
$ psql -c "create user postgres createdb;"
$ psql -c "create database postgres;"
$ psql -c "create database acidjs;" -U postgres
$ npm test
1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.0

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

10 years ago

0.0.2

10 years ago