spincycle
Version:
A reactive message router and object manager that lets clients subscribe to object property changes on the server
58 lines (40 loc) • 1.1 kB
text/coffeescript
pg = require('pg')
class PostgresqlPersistence
constructor: () ->
= []
connect: ()=>
conString = "postgres://peter:foobar@localhost/qp"
pg.connect conString,(err, client, done) =>
if err
console.log 'PostgreSQL ERROR connecting: '+err
console.dir err
else
= done
= client
console.log 'Created PostgreSQL successfully'
getDbFor: (_type) =>
q = defer()
type = _type.toLowerCase()
db = [type]
if not db
.query 'SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name = \''+type+'\' )', (err, result) =>
if (err)
throw err
else
if result.rows.length == 0
# create table according to model type schema
else
[type] = type
q.resolve(type)
else
q.resolve(type)
return q
all: (_type, cb)=>
rv = []
type = _type.toLowerCase()
.then (db) =>
get: ()=>
set: ()=>
remove: ()=>
module.exports = PostgresqlPersistence