0.1.8 • Published 11 years ago

postgresql-orm v0.1.8

Weekly downloads
2
License
MIT
Repository
github
Last release
11 years ago

npm install postgresql-orm --save

var ORM = require('postgresql-orm')

ORM.setup('postgres://<username>:<password>@<hostname>/<dbname>')

var userEntityDefinition = {
	name: 'users', // will match table with name 'users'
	attributes: {
		email: {
			type: 'character varying',
			unique: true
		},
		firstName: {
			type: 'character varying'
		},
		lastName: {
			type: 'character varying'
		},
		createdDate: {
			type: 'timestamp with time zone'
		}
	}
}

var User = ORM.define(userEntityDefinition)

User.dropTable(function(err) {
	// existing table dropped
})

User.createTable(function(err) {
	// table created
})

// save or update, depending on the presence of an 'id' attribute
User.save({firstName: 'John'}, function(err, savedEntity) {
	// do something
	savedEntity.id
})

User.create({firstName: 'John'}, function(err, createdEntity) {
	// do smthg
})

User.update({id: 123, lastName: 'Doe'}, function(err, updatedEntity) {
	// do smthg
})

User.load({id: 123}, function(err, loadedEntity) {
	// do smthg
})

Data Types

The data types available are those available in postgresql

notes

  • for each table, an auto-generated type column named id is required
  • attributes starting with an underscore are reserved
  • camel case attributes are transformed into snake case.
    • For example attributeName will map to column attribute_name - the behaviour is undefined if there are 2 attributes attributeName and attribute_name for one entity type as the resulting column names are the same.
0.1.8

11 years ago

0.1.7

11 years ago

0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago