node-orm2使用

2014/07/22

https://github.com/dresende/node-orm2

npm install orm --save

The drivers and versions that are tested.

driver npm package version
mysql mysql 2.0.0-alpha9
postgres redshift pg 2.6.2 [1]
sqlite sqlite3 2.1.7
mongodb mongodb 1.3.19

[1] If you’re connecting to Heroku, use version 2.5.0.

sqlite

字符串连接数据库

连接字符串语法: driver://username:password@hostname/database?option1=value1&option2=value2..

https://github.com/dresende/node-orm2/issues/20 https://github.com/dresende/node-orm2/commit/691470accace4e59079960410e20140ee556de4b

// if use sqlite
orm.connect('sqlite:///path/to/file', function (err, db) {
  // ...
});

定义数据模型