# promiseland-pg

> a promising connection object and a storage module

Latest version **0.0.3** (published 2015-04-12) · LGPLv3 license · 0 weekly downloads

## Install

```sh
npm install promiseland-pg
pnpm add promiseland-pg
yarn add promiseland-pg
bun add promiseland-pg
```

## 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.0.3 |
| Published | 2015-04-12 |
| First published | 2015-04-11 |
| Weekly downloads | 0 |
| License | LGPLv3 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+5 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matthias Behrens |
| Maintainers | sol |
| Keywords | promiseland, pg, postgres, postgresql, storage, savable |

## Links

- npm: https://www.npmjs.com/package/promiseland-pg
- Repository: https://github.com/soliton4/promiseland-pg
- Homepage: http://promiseland.technology
- Issues: http://github.com/soliton4/promiseland-pg/issues
- npm.io page: https://npm.io/package/promiseland-pg

## Dependencies (3)

- [pg](https://npm.io/package/pg.md) 4.1.x
- [lodash](https://npm.io/package/lodash.md) 1.3.x
- [sliced](https://npm.io/package/sliced.md) 0.0.x

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2015-04-12
- 0.0.2 — 2015-04-11

## README

promiseland-pg
==============

a promising connection object and storage module

connect:
========

```
var Con = require "promiseland-pg";
  
var con = new Con("postgres://postgres:pwd@localhost/mydb");
```

query:
======

```
console.log(*con.query("select * from mytable"));
```

reading table definition:
=========================

```
var myTableDescription = *con.tableDescription({name: "mytable", schema: "myschema"}); // schema is optional

var myTable = myTableDescription.table;   // a node-sql object describing the table
var indexes = myTableDescription.indexes; // array of indexes
var pk = myTableDescription.pk;           // the primary keyk
```

see  [node-sql](https://github.com/brianc/node-sql) for details on the table description objects.  


creating/modifying a table without desroying existing data:
===========================================================

this is one of the advanced and very convenient features. you can provide a node-sql table object to create.  
before the table will be created the db is scanned for a existing object of the same name.  
if a existing table is found the existing data will be transformed to the new description.  
(please only use this feature with productive data when you have a backup)  

```
  var sql = con.sql;

  var myTable = sql.define({
    name: 'myTable',
    schema: "public", // optional
    columns: [{
      name: 'id',
      dataType: "integer",
      primaryKey: true
    }, {
      name: 'someval',
      dataType: 'char(30)'
    }, {
      name: 'someotherval',
      dataType: 'varchar'
    }]
  });

  *con.createTable({
    table: myTable,
    indexes: []     // optional
  });
```

promiseland storage:
====================

Now to the most advanced feature. A promiseland savable storage module is provided. See [promiseland savable](https://github.com/soliton4/promiseland/wiki/savable) for details.  

a complete promiseland module:
```
<{ name: "myModule" }>

var Con = require "promiseland-pg";
var con = new Con("postgres://postgres:pwd@localhost/mydb");
  
promiseland.classSystem.setStorageEngine(con.storageHandler());

class type savable MyClass {
  constructor: (var pk){
    
  },
  a: 1,
  var meta { type: "int" } b: 2,
  var c: "some default data",
  y: "other default data"
};
  
MyClass instance1 = *new MyClass("yy"); // load data with pk "yy"
  
console.log(instance1.c);
  
instance1.c = "something else";
instance1.b = 4;
  
*instance1.save();
```

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