jdp

jungles-data-postgres

Data for Jungles using Postgresql

Showing:

Popularity

Downloads/wk

78

Maintenance

No Maintenance Data Available

Package

Dependencies

6

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Jungles Data Postgresql

API

Setup

var data = require('jungles-data-postgres')({
  user: 'james',
  password: '1234',
  database: 'jungles',
  host: '127.0.0.1'
});

data.setup(); // Creates table called instances

Find

var result = data.find(<query object>);

result.many(function (response) {
  // Always called
  // response: Array (can be empty)
});

result.one(function (response) {
  // called when there is atleast one result
  // { id, name, path, arrange, sort, ..data.. }
});

result.empty(function () { 
  // called when result is empty
});

result.error(function (error) {
  // error
});

Remove

var result = data.remove(<query object>);

result.success(function () { });

Save (create, update)

// Create
var result = data.save({ type: 'product', parent: 0, name: 'snowboard', arrange: '0' });
result.success(function () {});

These fields are required to create. Extra fields get json stringified and added to the data column.

// Update
var result = data.save({ id: 1, name: 'skateboard' });
result.success(function () {});

Because there is an id it knows it's an update.

Tree

var result = data.tree(<query object>); 

result.success(function (tree) { });

Structure

{
  id: 1,
  name: 'snowboard',
  path: '/snowboard',
  type: 'product',
  sort: '/0',
  arrange: 0,
  children: [
    {
      id: 2,
      name: 'tags',
      path: '/snowboard/tags',
      type: 'tags',
      sort: '/0/0',
      arrange: 0,

      children: [
        {
          id: 3,
          name: 'red',
          path: '/snowboard/tags/red',
          type: 'tag',
          sort: '/0/0/0',
          arrange: 0,
        }
      ]
    }
  ]
}

Query object examples

{ id: 5} 
// SELECT * FROM instances where id = 5;

{ path: /.*/ } 
// SELECT * FROM instance WHERE path ~ .*;

{ path: /.*/, id: 5 } 
// SELECT * FROM instances WHERE path ~ .* and id = 5;

Test

mocha.js and should.js is needed. Tests are run against a real database so you need to have postgresql. Check specs/db for database settings.

make test

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial