BackboneORM was designed to provide a consistent, polystore ORM across Node.js and the browser.
It was inspired by other great software and provides:
- Node.js-style callbacks and streams for a familiar asynchronous programming style
- MongoDB-like query language to easily slice-and-dice your data
- a REST controller enabling browser search bar queries and an optional paging format like CouchDB
Other great things:
- it provides a JSON-rendering DSL
- it solves the dreaded Node.js circular dependencies problem for related models
- it is compatible with Knockback.js
- it parses ISO8601 dates automatically
- BackboneMongo provides a CouchDB-like '_rev' versioning solution
- BackboneREST provides authorization middleware hooks and emits REST events
Modules
Out of the box, BackboneORM comes packaged with a memory store. Other modules:
- BackboneHTTP - remote storage over HTTP
- BackboneMongo - MongoDB
- BackboneSQL - PostgreSQL, MySQL
- BackboneREST - Express and Restify REST endpoint generator for BackboneHTTP
Examples (CoffeeScript)
# Find the Project with id = 123 ProjectfindOne id: 123 # Find the first Project named 'my kickass project' ProjectfindOne name: 'my kickass project' # Find all items with is_active = true Projectfind is_active: true # Find the items with an id of 1, 2 or 3 Projectfind id: $in: 123 # A shortcut for `$in` when we're working with ids Projectfind $ids: 123 # Find active items in pages Projectfind is_active: true$limit: 10$offset: 20 # Select named properties from each model Projectfind $select: 'created_at''name' # Select values in the specified order Projectfind $values: 'created_at''status' # Find active items in pages using cursor syntax (Models or JSON) Projectcursoris_active: truelimit10offset20toModels Projectcursoris_active: truelimit10offset20toJSON # Find completed tasks in a project projectcursor'tasks'status: 'completed'sort'name'toModels # Iterate through all items with is_active = true in batches of 200 Projecteach is_active: true$each: fetch: 200 consolelog "project: "; callback consolelog 'Done' # Stream all items with is_active = true in batches of 200 Projectstreamis_active: true$each: fetch: 200 pipe on'finish'-> consolelog 'Done' # Collect the status of tasks over days stats = Taskinterval $interval: key: 'created_at'type: 'days'length: 1 histogram = Taskstream_extendquery$select: 'created_at''status' pipehistogram on'finish'-> statspushhistogramsummary; callback consolelog 'Done'
Examples (JavaScript)
// Find the Project with id = 123Project; // Find the first Project named 'my kickass project'Project; // Find all items with is_active = trueProject; // Find the items with an id of 1, 2 or 3Project; // A shortcut for `$in` when we're working with idsProject; // Find all items with is_active = trueProject; // Select named properties from each modelProject; // Select values in the specified orderProject; // Find active items in pages using cursor syntax (Models or JSON)ProjecttoModels {});ProjecttoJSON {}); // Find completed tasks in a project sorted by nameprojecttoModels {}); // Iterate through all items with is_active = true in batches of 200Project; // Stream all items with is_active = true in batches of 200Project ; var stats = ;Task;
Please checkout the website for installation instructions, examples, documentation, and community!
For Contributors
To build the library for Node.js and browsers:
$ gulp build
Please run tests before submitting a pull request:
$ gulp test --quick
and eventually all tests:
$ npm test