An awesome, define-once, use anywhere ORM.
Note: These docs are in the process of being written. The code examples are up to date, but not exhaustive.
To use with NPM:
npm install --save intaglio
To use with Bower
bower install --save intaglio
To get up and running quickly with Node and MySQL, here's how you would instantiate the ORM:
var Intaglio = ;/*** Instantiate the MySQL repository that the ORM will bind to.*/var repository =;/*** Create an ORM to work with. This returns a promise because the ORM must wait* for the repository to become ready. The MySQL repository makes a few queries* on instantiation to get the database structure. We can't start using it until* these calls have completed.*/IntaglioORM;
Currently, Intaglio ships with a MySQL and a REST respository (designed to be used with the Intaglio based REST server) to get you up and running quickly. The MySQL repository will use database introspection to define your model schema so all you need to provide are the connection details to get started using with Node. The REST repository comes with a Request based driver as well as a jQuery based one to be used on the front end.
The ORM should be pretty easy to use, but there are some things to keep in mind. We made some design decisions to make the implentation simpler and easier to maintain.
The ORM will not care what names you use on the repository side, but it will normalize them to make it easier to code around. All model names and property names will be normalized to camelCase. Model names will also be made singular. So if your repository provides a model named
user_profiles, it will be normalized to
The ORM will expect some sort of primary key to bind to. Also, while multiple column keys can be used, they are not well tested, so if you use them, let us know what issues you run into.
In the following examples, we'll use a
user model that has the following schema:
// Create an empty user objectvar user = ORM;// Set a single value to the objectuser;// Set multiple values to the objectuser;// Save the object. This returns a promise.user;// Create an object with values and save itORM;
In order to make things easy to use, Intaglio relies on natural language chain style queries:
// Finds and returns the first model in the repository that has the firstName of DonnyORM;// Finds and returns all models in the repository that have the firstName of DonnyORM;// Finds a user with an id of 1ORM;
To add methods to models or override functionality, you can extend the model. If you override a method, you can access the original method using
// Extend the user modelORM;
The models in the ORM have a few built in events that you can bind to:
// Load WalterORM;
// Extend the user model to add a custom functionality that triggers a custom eventORM;var Walter Donny;// Load WalterORM;