Gresshelf
Gressshelf is a nodejs wrapper around postgresql jsonb columns. That allows you to use postgres like you would use a nosql database like MongoDB in schema(less) format.
usage
initialize gresshelf with the postgress connection details, and your application schema
let gs = let db = postgres: host : '127.0.0.1' user : 'your_database_user' password : 'your_database_password' database : 'myapp_test' schema: users: email: type: 'string' password: type: 'string' posts: title: type:'string' created_at type: 'date'
The schema is for type safety, but can be changed easily at application level without touching the db
insert items
db.table(tableName).insert(data, options)
;
// after initializing gresshelf// to insert a document into the users tablelet promise = db
- a random integer ID is generated for each inserted document
query items
db.table(tableName).filter(data, options)
;
// after initializing gresshelf// to query documents from the users tablelet promise = db // similar to saying, return fields where name == 'Jason Bourne' and tag === 'asset'
find a single item
- if you have the ID, you can fetch that particular document
db.table(tableName).getItem(id, options)
{ let one = await db; // { // id: '225669998854755', // data, // deleted: false, // create_at: date, // updated_at: date // }}
update item
db.table(tableName).updateItem(id, data, options);
[WARNING] updateItem replaces the whole document, therefore you should provide all the fields, even those that haven't changed.
// after initializing gresshelf// to update a document in the users tablelet promise = db