I am pleased to announce ActiveRecord.js, an open source object relational mapper (ORM) that supports multiple JavaScript environments:
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.
Whereas other projects have sought to directly port Rails' implementation of ActiveRecord to JavaScript, the approach here is different. Existing ActiveRecord aficionados who are used to the ultra succinct vocabulary of Rails' ActiveRecord implementation will instead find something well suited for JavaScript developers adapting the patterns refined by the Rails community (and some influences from Django) into powerful, easy to use APIs.
Example:
The library ships in a single file, has no external dependencies, and runs client side in all major browsers with or without access to a SQL database and can be used server side with mySQL and SQLite databases via Aptana Jaxer, the open source Ajax server with support for server-side JavaScript. All of the basic features you'd expect are present in this beta release: data validations, life-cycle callbacks, schema creation / migrations and relationships between models. As a beta it's quite stable, and we look forward to your use and feedback to make refinements before calling it 1.0. We're also working with some folks at Google, Mozilla, and Adobe to best achieve the support for JavaScript environments in the browser, on mobile devices, on the desktop and on the server.
Since one target use of this library is for client side stateful applications (using HTML, HTML5, Gears, Adobe AIR, etc...) we have some features that server side only libraries (Aptana Jaxer) don't need to support. One of the features I am most excited about is data synchronization. Although it is nascent, using the current implementation, you can find records or entire result sets and have those found objects automatically receive updates if the data they contain is changed by other queries, or records that should be contained in the result set are created or destroyed. This is marginally useful on its own, but when building user interfaces that depend on data being up to date, I've found it quickly becomes hard to imagine life without it. Synchronization between the client and server is not in the scope of this library yet, but it is on the radar.
If you look in GitHub you will see there is more than just ActiveRecord on the way. ActiveRecord.js is the first part of ActiveJS, a robust MVC framework that's being created explicitly for JavaScript and Ajax apps (and works with other Ajax libraries). I'll be blogging again on these other parts of ActiveJS when they are ready for a public beta, but for those who can't wait, you can find sneak peeks of them in the repo.
For now, enjoy the simplicity of ActiveRecord.js:
I'd also like to make a couple of notes that might preempt a FAQ:
Feel free to ask questions in the ActiveJS Google group. We also welcome pull requests in our GitHub repository if you have forked the project.
Enjoy!
-- Ryan Johnson and Aptana