
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
Modelize is a simple ORM written in JavaScript.
Apache License (version 2)
Modelize requires version 0.6.x of Node.js or higher. If you want to run the tests or work on model, you'll want Vows.
npm install modelize
Modelize currently implements an in-memory store. More adapters will follow, a socket.io binding is also planned.
Modelize uses a simple syntax for defining a model. It will look like this:
var UserModel = new Modelize('User', function() {
this.adapter('memory');
this.property('username', 'string', { required: true });
this.property('password', 'string', { required: true });
this.property('firstName', 'string', { defaultValue: 'John' });
this.property('lastName', 'string', { defaultValue: 'Doe' });
});
The following data types are currently supported:
Now you can create instances of your new fancy User model. It is easy too:
var user = UserModel.create({
username: 'jdoe',
password: 'fancymodels',
lastName: 'Smith'
});
Just use the following syntax:
// Getting properties
console.log(user.username());
console.log(user.password());
// Setting properties
user.password('modelize');
If you try to get a property which was not initialized yet, it will return the default value or undefined if there is none.
Remember: You must initialize/set all required properties before saving the model. Otherwise Modelize will throw an error.
user.save(); // Saves the model instance into the store
user.password('nodejs');
user.save(); // Updates the model instance in the store
user.remove(); // Removes the model instance from the store
Modelize offers a simple API for finding and sorting existing items/instances. Please remember, that an instance can only be found, if instance.save() was called.
The API is (as you might expect for a NodeJS library) asynchronous and the methods for querying are static methods on each model constructor.
Instances are always shared to save memory usage and keep the usage simple. This means:
var user1 = UserModel.create({
lastName: 'Doe'
});
var user2 = UserModel.create({
lastName: 'Doe'
});
UserModel.find({lastName: 'Doe'}, function(err, data) {
// data[0] is the same instance as user1
// data[1] is the same instance as user2
user1.lastName('Smith');
console.log(user1.lastName() == data[0].lastName()) // Is true
});
Use the findOne method to find a single item. You can specify a set of query parameters in the form of an object-literal. In the case of multiple results, it will only return the first one. If no result can be found, the return value is undefined.
UserModel.findOne({username: 'jdoe'}, function(err, user) {
if(err) throw err;
if(user === undefined) throw new Error('User not found!');
console.log(user);
});
Use the find method to find lots of items. Pass it a set of query parameters in the form of an object-literal, where each key is a field to compare and the value is a simple value for comparison. (equal to)
UserModel.find({lastName: 'Smith'}, function(err, data) {
if(err) throw err;
// Data is now array filled with all results found
});
If you want to compare an object, you can also give a set of query parameters like this: {stats: {experience: 37, age: 19}}
Modelize Javascript ORM - © 2012-2013 P. Mathis (pmathis@snapserv.net)
FAQs
Simple ORM in JavaScript
We found that modelize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.