# gresshelf

> Gressshelf is a nodejs wrapper to postgresql jsonb columns. That allows you to run, nosql like, schemaless (kind of), based node applications on top of postgres, while still getting the traditional ACID features of the DB.

Latest version **0.1.1** (published 2017-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install gresshelf
pnpm add gresshelf
yarn add gresshelf
bun add gresshelf
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-03-29 |
| First published | 2017-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Alloys Mila |
| Maintainers | mofax |
| Keywords | postgres |

## Links

- npm: https://www.npmjs.com/package/gresshelf
- Repository: https://github.com/mofax/gresshelf
- Homepage: https://github.com/mofax/gresshelf#readme
- Issues: https://github.com/mofax/gresshelf/issues
- npm.io page: https://npm.io/package/gresshelf

## Dependencies (3)

- [co](https://npm.io/package/co.md) ^4.6.0
- [pg](https://npm.io/package/pg.md) ^6.1.2
- [knex](https://npm.io/package/knex.md) ^0.12.7

## Recent versions

- 0.1.1 (latest) — 2017-03-29
- 0.1.0 — 2017-03-23
- 0.0.3 — 2017-03-09
- 0.0.2 — 2017-03-06
- 0.0.1 — 2017-02-26
- 0.0.0 — 2017-02-26

## README

# Gresshelf

Gressshelf is a nodejs wrapper around postgresql [jsonb](https://www.postgresql.org/docs/9.4/static/datatype-json.html) 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

```js
let gs = require('./gresshelf')
let db = new gs({
  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)`;

```js
// after initializing gresshelf
// to insert a document into the users table
let promise = db.table('users').insert({
  name: 'Jason Bourne',
  tag: 'asset'
}).then(changes => {
  // item inserted
})
```

 - a random integer ID is generated for each inserted document

## query items
`db.table(tableName).filter(data, options)`;

```js
// after initializing gresshelf
// to query documents from the users table
let promise = db.table('users').filter({
  name: 'Jason Bourne',
  tag: 'asset'
}).then(results => { // returns an array of values
  // results == []
})

// 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)`

 ```js
 async function () {
  let one = await db.table('users').getItem('225669998854755');
  // {
  //  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.

```js
// after initializing gresshelf
// to update a document in the users table
let promise = db.table('users').update('225669998854755', {
  name: 'Matt Damon',
  tag: 'nothing'
}).then(results => { // returns an array of values
  // results == integer showing number of rows changed
})

---
_Source: https://npm.io/package/gresshelf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
