ActiveRecord.jsJavaScript 对象映射框架
ActiveRecord.js 是一个开源的JavaScript 对象映射框架,包括:
- Google Gears (client-side persistence)
- In Memory (if no SQL server is available on the client)
- Adobe AIR (client-side persistence)
- SQLite and MySQL (via Aptana Jaxer, the open source Ajax server)
- additional environments (like HTML5) expected to come through working with the community on the project
ActiveRecord.js abstracts away underlying SQL commands so that JavaScript developers can have a unified API for storing, finding, selecting and retrieving objects and their data using the ActiveRecord pattern popularized by the Ruby on Rails community.
示例代码:
- var User = ActiveRecord.define('users',{
- username: '',
- email: ''
- });
- User.hasMany('articles');
- var ryan = User.create({
- username: 'ryan',
- email: 'rjohnson@aptana.com'
- });
- var Article = ActiveRecord.define('articles',{
- name: '',
- body: '',
- user_id: 0
- });
- Article.belongsTo('user');
- var a = Article.create({
- name: 'Announcing ActiveRecord.js',
- user_id: ryan.id
- });
- a.set('name','Announcing ActiveRecord.js!!!');
- a.save();
- a.getUser() == ryan;
- ryan.getArticleList()[0] == a;
评论