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

jeloquent

v4.0.3

Published

micro framework / memory orm model store

Downloads

36

Readme

jeloquent

npm jeloquent npm jeloquent npm jeloquent npm jeloquent Node.js CI Scrutinizer Code Quality

Is an orm memory store for javascript.

Main goals are:

  • to quickly select models and/or his relations using primaryKeys and foreignKeys
  • automated indexing of relations
  • use the relation names of laravel eloquent
  • a simple setup of the relations
  • return array collections of relations
  • add easy accessors for relations on model
  • keep the package lightweight and for modern browsers

Speed test with more than 600 000 entities

5000 times a selection of an entity and 3 of his relations of all relation types, average speed in this test was 0.07ms :smile: speed test

Quick Setup Guide

Quick Setup Guide

Documentation

Documentation

Install

npm jeloquent

npm install jeloquent

Playground

Edit shy-rgb-681hz

Usage

Class example

import {Model, Field, HasMany, BelongsTo} from 'jeloquent';
import Team from "./Team.js";
import Comment from "./Comment";

export default class User extends Model {
    constructor() {
        const fields = [
            new Field('id', true),
            new Field('name'),
            new Field('team_id'),
            new BelongsTo(Team),
            new HasMany(Comment),
        ];
        super(fields);
    }
}

import {Model, Field, HasMany, HasManyThrough} from 'jeloquent';
import User from "./User";
import Comment from "./Comment";

export default class Team extends Model {

    constructor() {
        const fields = [
            new Field('id', true),
            new Field('name'),
            new HasMany(User),
            new HasManyThrough(Comment, User),
        ];

        super(fields);
    }
}

import {Model, Field, BelongsTo} from 'jeloquent';
import User from "./User";

export default class Comment extends Model {

    constructor() {
        const fields = [
            new Field('id', true),
            new Field('title'),
            new Field('text'),
            new Field('user_id'),
            new BelongsTo(User),
        ];

        super(fields);
    }
}

Store example


import {Database, Store} from 'jeloquent';
import {User, Team, Comment} from './Models';

const models = [
    User,
    Team,
    Comment,
];

const store = new Store();
store.add(new Database('chess', models));
store.use('chess');

Add data to table

User.insert([
    {id: 1, name: 'name', 'team_id': 1},
    {id: 2, name: 'name 2', 'team_id': 1}
]);

Add one model or temporary model to table

const newUser = new User();
newUser.name = 'New User';
newUser.team_id = 1;
newUser.save();

It generates a temporary key that can be used to find the model

User.find('_1');

When you update the primary key, then the primary key index will be replaced.

const newUser = User.find('_1');
newUser.id = 1234;
newUser.save();

//now use 
User.find(1234);

Selecting data from tables

User.find(1);
User.find([1, 5, 9]);
User.all();
User.ids();

Updating table data

User.update(model);
User.delete(1);

Fetching relation

// return Team object or null
User.find(1).team;

//returns array of comments or empty array
User.find(1).comments;

// Has many trough
// same as Team.select(1).users.reduce((array, user) => {array.push(...user.comments)}, []);
Team.find(1).comments;

Relations getters

//BelongsTo

//return true or false
User.find(1).hasTeam 

//HasMany

User.find(1).hasComments

// returns number of comments of user 1
User.find(1).commentsCount

Filter on relation properties


User.all().filter(user => user.commentsCount > 5);
User.all().filter(user => !user.hasComment);

Getting model and direct relations as json object


const jsonDataOfUser = User.find(1).toJson();

Results in

{ 
    "comments": [
        {"id": 1, "title": "Hello", "text": "Bla Bla", "user_id": 1}, 
        {"id": 2, "title": "Hello 2", "text": "Bla Bla Bla", "user_id": 1}
    ],
    "id": 1,
    "name": "test 1",
    "team_id": 1,
    "team": {"id": 1, "name": "name"}
}