npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ilorm

v0.15.2

Published

Core package of ilorm ORM

Downloads

31

Readme

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

| Function | Description | |:--------:|-------------| | 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 :

| Function | Description | |:--------:|-------------| | 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

| Function | Description | |:--------:|-------------| | 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

| Function | Description | |:--------:|-------------| | [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 :

| Function | Description | |:--------:|-------------| | [field].set(value) | Set the value of the field | | [field].inc(value) | Incremente the value of the field by the given value |

Operations

| Function | Description | |:--------:|-------------| | 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();

| Function | Description | |:--------:|-------------| | save() | Save the instance in the database (auto insert or update) | | remove() | Delete the instance from the database |