sqldb-orm

1.1.0 • Public • Published

db-orm

About

a sql-orm mini package.

can use mysql or sqlite3 database.

How use

First make a mysql-config.js file

// mysql config file like this:
module.exports = {
    connectionLimit: 10,
    host: '127.0.0.1',
    user: 'root',
    password: 'your password',
    port: 3306,
    database: 'db-name'
}

And then new class

//use mysql
let orm=require('sqldb-orm');
let config=require('./mysql-config');

async function main(){
    let sqlDal=await orm.getClass('mysql',config,'tb_user',true);
    let list=await sqlDal.findAll();
    console.log(list);
}
main();
//use sqlite3
let orm=require('sqldb-orm');
let config='./test.db3';
async function main(){
    let sqlDal=await orm.getClass('mysql',config,'tb_user',true);
    let list=await sqlDal.findAll();
    console.log(list);
}
main();

API

testConnect(dbFile):Promise<Array>

query(sqlStr, params):Promise<Array>

insert(entity):Promise<Array>

truncate():Promise<Array>

remove(whereStr):Promise<Array>

removeById(id):Promise<Array>

update(entity, whereStr):Promise<Array>

updateByParams(entity, where):Promise<Array>

updateById(entity, id):Promise<Array>

findAll(columns,orderStr):Promise<Array>

findById(id):Promise<Array>

findOne(query):Promise<Array>

findWithQuery(query):Promise<Array>

findTop(columns, count, whereStr):Promise<Array>

findCount(fromStr, whereStr):Promise<Array>

find(columns, whereStr, sortStr, count):Promise<Array>

findByPage(fieldStr, fromStr, whereStr, sortStr, pageIndex, pageSize):Promise<Array>

getTableNames(tableName):Promise<Array>

findColumnName(tableName):Promise<Array>

findMaxId(tableName):Promise<Array>

Package Sidebar

Install

npm i sqldb-orm

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

21.1 MB

Total Files

8

Last publish

Collaborators

  • lanmeng2022