rdb 介绍
rdb 是 Node.js 的一个 ORM 框架,支持 Postgres 和 MysqL 数据库。
特点:
示例代码:
var rdb = require('rdb'); var Customer = rdb.table('_customer'); Customer.primaryColumn('cId').guid().as('id'); Customer.column('cName').string().as('name'); Customer.column('cBalance').numeric().as('balance'); Customer.column('cRegdate').date().as('registeredDate'); Customer.column('cIsActive').boolean().as('isActive'); Customer.column('cPicture').binary().as('picture'); var db = rdb('postgres://postgres:postgres@localhost/test'); db.transaction() .then(getById) .then(printCustomer) .then(rdb.commit) .then(null, rdb.rollback) .then(onOk, onFailed); function getById() { return Customer.getById('a0000000-0000-0000-0000-000000000000'); } function printCustomer(customer) { var format = 'Customer Id: %s, name: %s, Balance: %s, Registered Date: %s, Is Active: %s, Picture: %s'; var args = [format, customer.id, customer.name, customer.balance, customer.registeredDate, customer.isActive, customer.picture]; console.log.apply(null,args); } function onOk() { console.log('Success'); console.log('Waiting for connection pool to teardown....'); } function onFailed(err) { console.log('Rollback'); console.log(err); }
rdb 官网
https://www.npmjs.com/package/rdb
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。