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

tiny-entity2

v1.5.8

Published

A simple and easy to use ORM framework, support NEDB, IndexedDB, MySQL and Sqlite and other commonly used database

Downloads

17

Readme

tiny-entity2

Table of Contents

Install

$ npm install tiny-entity2

Introduction

This is a ORM framework support Mysql and Sqlite3.

Define

you can define an entity model like this:

@Define.Table({ TableName: "person" })
export class Person extends EntityObjectMysql<Person> {
    @Define.PrimaryKey()
    id: string;

    @Define.Column({ 
        DataType: Define.DataType.Decimal, 
        DataLength: 11, 
        DecimalPoint: 3 
    })
    weight: number;

    @Define.Column()
    name: string;

    @Define.Column({ 
        DataType: Define.DataType.INT, 
        DataLength: 11 
    })
    age: number;

    @Define.Column({ DataType: Define.DataType.BIGINT })
    birth: number;
}

you can use PrimaryKey() define a primarykey for an entity , and also use Column() define a field. you can use some parameters for Column() like this:

@Define.Column({ 
        DataType: Define.DataType.Decimal, 
        DataLength: 11, 
        DecimalPoint: 3 
})

method list: PrimaryKey(opt?: PropertyDefineOption): define a primarykey faster then Column().

Column(opt?: PropertyDefineOption) define a field. and also you can use this function define a primaryKey.

Mapping(opt: PropertyDefineOption) define a mapping. it is used to deal with database foreignKey .

interface PropertyDefineOption{
    DataType?: DataType;
    DefaultValue?: any;
    NotAllowNULL?: boolean;
    DataLength?: number;
    ColumnName?: string;
    IsPrimaryKey?: boolean;
    ForeignKey?: { ForeignTable: string; ForeignColumn: string; IsPhysics?: boolean; };
    DecimalPoint?: number;
    IsIndex?: boolean;
    Mapping?: string;
    MappingType?: MappingType;
    MappingKey?: { FKey: string, MKey?: string } | string;
}

enum DataType {
        VARCHAR,
        TEXT,
        LONGTEXT,
        Decimal,
        INT,
        BIGINT,
        BOOL,
        Array,
        JSON
    }

Query

query datas from table, return array.

let list = await ctx.Person.Where(x => x.age > age, { age }).ToList();
let list = await ctx.Person.Where(x => x.name.indexOf($args1), { $args1: params.name }).ToList();

using left join:

let list = await ctx.Person
            .Join(ctx.Account)
            .On((m, f) => m.id == f.personId)
            .Contains<Account>(x => x.amount, values2, ctx.Account)
            .ToList();

query single entity

let list = await ctx.Person.First(x => x.name.indexOf($args1), { $args1: params.name });

using transcation:

await Transaction(new TestDataContext(), async (ctx) => {
                //insert 10 persons to database;
                for (let i = 0; i < 10; i++) {
                    let person = new Person();
                    person.id = Guid.GetGuid();
                    person.name = "likecheng" + i;
                    person.age = 30 + i;
                    person.birth = new Date("1987-12-1").getTime();
                    if (i == 9)
                        throw ' transaction error';
                    await ctx.Create(person);
                }
            });

Command

you need install tiny-entity2 global

$ npm install tiny-entity2 -g

at first you need to create the tinyconfig.json in your project. this file provide some options to command.

{
    "outDir": "./test",
    "modelLoadPath": [
        "./test/models"
    ],
    "modelExportPath": [
        "./models"
    ],
    "ctxExportPath": "",
    "configFilePath": "./config",
    "outFileName": "testDataContext.ts",
    "databaseType": "mysql",
    "packageName": "../mysql/dataContextMysql"
}

property description:

  • outDir: directory of file output.
  • modelLoadPath: directory of model file import.
  • modelExportPath: directory of model file export.
  • ctxExportPath: directory of data context file export.
  • configFilePath: directory of database config file .
  • outFileName: the name of data context file.
  • databaseType: database type, 'mysql' or 'sqlite'.
  • packageName: path of data context engine. now only support dataContextMysql and dataContextSqlite

use command 'gctx' create a dataContext.ts file.

tiny --gctx ./tingconfig.json

use command 'gdb' create a new database file .

tiny --gdb ./tingconfig.json

use comman d 'gop' create a update log and excute to database.

tiny --gop ./tingconfig.json

you can create different tinyconfig.json for different domain models.