Easy Model
install
npm i @feiye/easy-model
example
const mysql = require('mysql');
const { model, Query } = require('@feiye/easy-model');
const conn = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
database: 'test',
});
const query = new Query(conn);
const User = model('user');
const id = await User(query).create({ name: 'yf', age: 11 });
console.log(id);
const user = await User(query).findByPk(id);
user.name = 'yefei';
user.save();
const users = await User(query).find().all();
const users = await User(query).find().limit(10).all();
const users = await User(query).find({ age: 11 }).all();
const count = await User(query).count();
const count = await User(query).count({ age: 11 });
const count = await User(query).find({ age: 11 }).count();
const exists = await User(query).exists({ id: 1 });
const exists = await User(query).find({ age: 11 }).exists();
const updatedCount = await User(query).find({ id: 1 }).update({ name: 'yf', age: 11 });
const user = await User(query).findByPk(1);
const deletedCount = await user.delete();
query.transaction(() => {
const user = await User(query).findByPk(1);
await user.delete();s
});
Related projects
mysql-easy-query
sql-easy-builder
s