1.0.5 • Published 6 years ago
@muzikanto/sql-orm v1.0.5
SQL query builder and connect request middleware
Create Model
const model = Model("user");
model.use(async (query: string) => {
// todo
return [] as Rows;
});
Use Model
model
.select(['name', 'age']
.where({age: 20})
.execute<Array<{ test: number }>>()
.then(rows=>{});
----- OR -----
const select = model.select(['name', 'age'];
select.where({age: 20});
select
.execute<Array<{ test: number }>>()
.then(rows=>{});
----- OR -----
const sqlQuery = model
.select(['name', 'age']
.where({age: 20})
.query();
insert
model
.insert({ name: "Maxim", age: 20 })
.execute()
.then(rows);
select
model
.select(['name', 'age']
.join("JOIN city ON user.city_id=city.id")
.where({age: 20})
.limit(10)
.offset(20)
.order('name')
.group(['name'])
.execute()
.then(rows=>{});
update
model
.update({ age: 20 })
.join("JOIN city ON user.city_id=city.id")
.where({ age: 19 })
.execute()
.then(rows => {});
delete
model
.delete()
.join("JOIN city ON user.city_id=city.id")
.where({ age: 20 })
.execute()
.then(rows => {});