ActiveRecord.js - JavaScript 对象映射框架


未知
跨平台
JavaScript

软件简介

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’);
    1. var ryan = User.create({
  6. username: ‘ryan’,
  7. email: 'rjohnson@aptana.com
  8. });
    1. var Article = ActiveRecord.define(‘articles’,{
  9. name: ‘’,
  10. body: ‘’,
  11. user_id: 0
  12. });
  13. Article.belongsTo(‘user’);
    1. var a = Article.create({
  14. name: ‘Announcing ActiveRecord.js’,
  15. user_id: ryan.id
  16. });
  17. a.set(‘name’,’Announcing ActiveRecord.js!!!’);
  18. a.save();
    1. a.getUser() == ryan;
  19. ryan.getArticleList()[0] == a;