0.0.15 • Published 3 years ago
lgnvpr-nodejs v0.0.15
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