ActiveRecord.jsJavaScript 对象映射框架

联合创作 · 2023-09-22 18:02

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.


示例代码:



  1. var User = ActiveRecord.define('users',{  

  2.     username: '',  

  3.     email: ''  

  4. });  

  5. User.hasMany('articles');  

  6.   

  7. var ryan = User.create({  

  8.     username: 'ryan',  

  9.     email: 'rjohnson@aptana.com'  

  10. });  

  11.   

  12. var Article = ActiveRecord.define('articles',{  

  13.     name: '',  

  14.     body: '',  

  15.     user_id: 0  

  16. });  

  17. Article.belongsTo('user');  

  18.   

  19. var a = Article.create({  

  20.     name: 'Announcing ActiveRecord.js',  

  21.     user_id: ryan.id  

  22. });  

  23. a.set('name','Announcing ActiveRecord.js!!!');  

  24. a.save();  

  25.   

  26. a.getUser() == ryan;  

  27. ryan.getArticleList()[0] == a; 

浏览 19
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报