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

es-entity

v4.2.1

Published

ORM framework for Node js based on Ecmascript 6 and Typescript.

Downloads

537

Readme

es-entity

ORM framework for Node js based on Ecmascript 6 and Typescript.

Contributors

Nitin Bansal https://github.com/nitinbansal1989

Installation

$ npm install es-entity

Usage

Create DB context and provide connection configuration.

const es = require("es-entity");

Entity Class

Entity class is the reference to the table in the database. The property in this class are field objects which refers to the columns of the table.

Note: The class members are camel cased from the snake case database columns. Annotation for custom column name will be implemented in future.

class Employee {
    constructor() {
        this.id = new es.Number();
        this.name = new es.String();
        this.description = new es.String();
    }
}

DB Configuration

Context is provided with the connection parameters of the database to connect.

var config = new es.ConnectionConfig();
config.handler = "mysql";
config.hostname = "localhost";
config.name = "mysql";
config.username = "root";
config.password = "application";
config.database = "test";

Context

Context class is created which extends from es.Context. This class works as database context for all your queries. The property in this class as queryable object to the respective classes.

const Employee_1 = require("./Employee");
class EmpContext extends es.Context {
    constructor(config, entityPath) {
        super(config, entityPath);
        this.employees = new es.DBSet(Employee_1.default);
        this.init();
    }
}

Provide the database config object and mapping folder object to the context object to bind.

const EmpContext_1 = require("./modal/EmpContext");
var context = new EmpContext_1.default(config);

Operations

Select Entities

let p = context.employees.where((a) => {
    return (a.id.lt(q)).or(a.id.eq(2));
}).list();

p.then((v) => {
    for (var i = 0; i < v.length; i++) {
        var j = v[i];
        console.log("id: " + j.id + ", name: " + j.name + ", desc: " + j.description);
    }
});

Select Entity By Id

let p = context.employees.get(1);

p.then((v) => {
    console.log("id: " + v.id + ", name: " + v.name + ", desc: " + v.description);
});

Updating Entity

v.description.set("test update 2");
let p = context.employees.update(v);
p.then((v) => {
    console.log("id: " + v.id + ", name: " + v.name + ", desc: " + v.description);
    console.log("updated");
});

Inserting Entity

let a = context.employees.getEntity();
a.name.set("name 2");
a.description.set("desc insert 2");
let p = context.employees.insert(a);
p.then((v) => {
    console.log("id: " + v.id + ", name: " + v.name + ", desc: " + v.description);
    console.log("inserted");
});

Deleting Entity

let p = context.employees.delete(v);
p.then(() => {
    console.log("deleted");
});

Note: Currently it is very basic and only supports mysql. Please provide suggestions if any.