Socket
Book a DemoInstallSign in
Socket

ilorm

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ilorm

Core package of ilorm ORM

0.15.2
latest
npmnpm
Version published
Weekly downloads
33
1000%
Maintainers
1
Weekly downloads
 
Created
Source

ilorm (I Love ORM)

New way to manipulate data with NodeJS.

.github/workflows/test.yaml .github/issues ./LICENCE Coverage Status Total alerts Language grade: JavaScript

You can found example and documentation on the Official Ilorm website

Why a new ORM ?

  • Elegant way to separate database from business logic.
  • Easy way to create powerful plugins using the "class" inheritance.
  • Universal database / data source connector (MongoDB, SQL, Redis, REST, CSV...).
  • Use newest feature of ECMAScript (modern javascript).

Features

  • Universal connector to bind every kind of database or data source.
  • Powerful plugin ecosystem
  • Query builder
  • Data validation

# Contributing Please, refer to our code of conduct before starting and to our contributing guide.

Initialize

Schema

With a Schema you define the way your data are represented.

const ilorm = require('ilorm');
const schema = ilorm.schema;

const userSchema = schema.new({
  firstName: schema.String().required(),
  lastName: schema.String().required(),
  children: schema.Array(schema.reference('User')),
  birthday: schema.Date(),
  weight: schema.Number().min(5).max(500)
});

ilorm.schema

FunctionDescription
static new( schema )Create a new ilorm schema.
static string()Instantiate a Field/String
static number()Instantiate a Field/Number
static boolean() Instantiate a Field/Boolean
static date() Instantiate a Field/Date
static reference() Instantiate a Field/Reference

All Fields

All Fields are children of the class BaseField. This class contains this method :

FunctionDescription
required()The field is required for create an object (per default not required).
default(value)  Set a precise value for default (if you do not set a value at creation).

Field/Number

Represent a javascript number.

Field/String

Represent a javascript string.

Field/Boolean

Represent a javascript boolean.

Field/Date

Represent a javascript date.

Field/Reference

Represent a javascript reference to another instance.

Models

const ilorm = require('ilorm');
const ilormMongo = require('ilorm-connector-mongo');

const userSchema = require('./schema');
const userModel = ilorm.newModel({
  name:'User',
  connector: ilormMongo({ db }),
  schema: userSchema,
});

userModel.query()
  .firstName.is('Smith')
  .findOne()
  .then(user => {
    user.weight = 30;
    return user.save();
  });

ilorm.model

FunctionDescription
query()  Instantiate a Query targeting the current Model

Query

Fields

In a query, every field present in the schema could be use to build the query. The [field] part in further documentation are every field declared in your specific schema.

Exemple of query

// if your schema is something like this ;
const schema = ilorm.schema({
  firstName: ilorm.String().required(),
});

// You could write query like this :
const user = await User.query()
    .firstName.is('Smith')
    .findOne();

Filters

FunctionDescription
[field].is(value)Check if the field is equal value
[field].isNot(value)Check if the field is not equal with value
[field].isIn(arrayOfValue)Check if the field value is one of the array value
[field].isNotIn(arrayOfValue)Check if the field value is none of array value
[field].between(min, max)Check if the value is between min and max (include)
[field].min(value)Check if the value is equal or superior than the value
[field].max(value)Check if the value is equal or inferior than the value
[field].linkedWith(value)Check if the field (reference) is linked with another model, id, ...

Update

Used for update or updateOne query only :

FunctionDescription
[field].set(value)Set the value of the field
[field].inc(value)Incremente the value of the field by the given value

Operations

FunctionDescription
 find()Run the query and return a promise with the result (array of instance).
 findOne()Run the query and return a promise the result (instance).
 count()Count the number of instance and return it.
 stream()Run the query with a stream context could be the best solution for big query.
remove()Remove the instance which match the query.
 removeOne()Remove only one instance which math the query.
 update()Used to update many instance.
 updateOne()Used to update one instance.

Query.update

userModel.query()
  .firstName.is('Smith')
  .weight.set(30)
  .update();

Query.stream

userModel.query()
  .stream() //Return a standard stream
  .pipe(otherStream);

Instances

Instances are returned after a loading (find, or stream). It's a specific item loaded from the database. You can create a new instance from the model :

const instance = new userModel();
instance.firstName = 'Thibauld';
instance.lastName = 'Smith';
instance.save();
FunctionDescription
save()Save the instance in the database (auto insert or update)
remove()Delete the instance from the database

Keywords

orm

FAQs

Package last updated on 07 Nov 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.