0.0.15 • Published 3 years ago

lgnvpr-nodejs v0.0.15

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

LGNV NodeJS

As a CRUD support library for nodejs

Authors

Installation

install npm package with npm i lgnvpr-nodejs

These are libraries inherited from sequelize, check them out here

I have an object like this:

export class Product {
    id : string; 
    name : string; 
    price : number; 
    img : string;
    deletedAt : Date;
    createdAt: Date;
    updatedAt: Date; 
}

Define a product Reponsitory:

const productAdapter = new AdapterSequelize({
    modelDefine: {
        id: {
            type: DataTypes.STRING,
            field: 'username',
        },
        name: {
            type: DataTypes.STRING,
            field: 'password',
        },
        price: { 
            type: DataTypes.STRING, 
            field: 'first_name' 
        },
        img: {
            type: DataTypes.STRING,
            field: 'last_name',
        },
        deletedAt: {
            type: DataTypes.STRING,
            field: 'phone',
        },
        createdAt: {
            type: DataTypes.STRING,
            field: 'address',
        }, //You can configure some other properties for the column, See detail Sequelize
    }, // define entity on database, 
    name: 'products', // table_name
    urlConnect: "postgres:your_username:your_password@host/database_name",
});

Create or update entity

productAdapter.save(entity); // entity you want save to database 

productAdapter.saveBulk(entity); // create or update many entity 

productAdapter.createBulk(entitys); // create many entity 

productAdapter.updateBulk(entitys); // update many entity 

Remove entity

productAdapter.remove({id : "id_entity"}); // id of entity

Get list by paging

// The fields may not be passed, it will take the default value
productAdapter.list({
    page : 1, 
    pageSize : 20,
    search : "abc",
    searchFields : ["name"],
    sort : ["-name"],
    filter : {
        name : "abc",
        id : "uuid"
    },
    query : {} // query of sequelize
}); // id of entity

Get list

// The fields may not be passed, it will take the default value
productAdapter.find({
    limit : 0, 
    offset : 1000,
    search : "abc",
    searchFields : ["name"],
    sort : ["-name"],
    filter : {
        name : "abc",
        id : "uuid"
    },
    query : {} // query of sequelize
}); // id of entity

Query by paging

For complex queries with paging, search, and sort functions. and now it's so easy

// The fields may not be passed, it will take the default value
productAdapter.queryByPagination("select * from ....",{
    replacements : ... // see detail in sequelize lib
} ,{
    limit : 0, 
    offset : 1000,
    search : "abc",
    searchFields : ["name"],
    sort : ["-name"],
    filter : {
        name : "abc",
        id : "uuid"
    },
    query : {} // query of sequelize
}); // id of entity
0.0.14

3 years ago

0.0.15

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago