Existing ORMs for Node provide too much functionality thus becoming too heavyweight.
Package pg-generic-dao provides extremelly simple and lightweight layer over PostgreSQL database for Node.
- No change tracker
- No identity map
- Simple mapper that maps underscore named fields to Node plain objects with camel-case named properties;
- CRUD operations;
- Filtering, sorting and paging support.
- Case of database field names is ignored.
- Underscores are removed, next letter after underscore is converted to uppercase letter. For example:
field
->field
,complex_field
->complexField
- Double underscore will be converted to nested Node object. For example:
very__complex_field
->{ "very": { "complexField": ... } }
- Every database table must contain "id" field. Currently only auto-incremented surrogate keys are supported.
var tableName = 'test_table_1';
// Fields: id, very_long_name, shortname
var columns = [ 'id', 'veryLongName', 'shortname' ];
var dao = new PgGenericDao({
connectTo: connStr,
table: tableName,
fields: columns
});
// Inserting new row
dao.save({
veryLongName: 'abc',
shortname: 'def'
})
.then(function (entity) {
})
.catch(function (err) {
});
// Updating existing row
dao.update({
veryLongName: 'abc',
shortname: 'def'
})
.then(function (entity) {
})
.catch(function (err) {
});
// Deleting existing row
dao.delete({ id: 1 })
.then(function (entity) {
})
.catch(function (err) {
});
// Find single row
dao.find(entity.id)
.then(function (foundEntity) {
})
.catch(function (err) {
});
// Find all rows
dao.all()
.then(function (result) {
})
.catch(function (err) {
});