huafua_dbmanager
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.4 • Public • Published

    hdb-mgr

    1. 简介

    pacakge是包含了两个自定义的数据库工具,分别用于操作mysqlsqlite

    2. 安装

    npm i hdb-mgr

    3. api 说明

    配置

    使用前可先配置一下,默认配置见包根目录下config.js,也可见mysql-dbsqlite-db下的config.js

    • DatabaseManager.useDatabase(dbname):指定数据库
    • DatabaseManager.useConfig(config:Config):重新指定各配置项,Config格式如下;
      interface Config {
        host: string;
        port: nunmber | string;
        user: string;
        password: string;
        dbname: string;
      }

    数据库操作 api

    • 查询

      • find(tablename,where,callback):void
      • find(tablename,callback):void
      • whereIn(tablename,condition,callback):void
      • whereLike(tablename,condition,callback):void
      • complexQuery(sql,callback):void
      • findSync(tablename,where):Promise
      • findSync(tablename):Promise
      • whereInSync(tablename,condition):Promise
      • whereLikeSync(tablename,condition):Promise
    • 删除

      • remove(tablename,where,callback):void
      • remove(tablename,callback):void
      • removeSync(tablename,where):Promise
      • removeSync(tablename):Promise
    • 更新

      • update(tablename,where,callback):void
      • update(tablename,callback):void
      • updateSync(tablename,where):Promise
      • updateSync(tablename):Promise
    • 新增

      • insert(tablename,item,callback):void
      • multiInsert(tablename,items,callback):void
      • insertSync(tablename,item):Promise
      • multiInsertSync(tablename,items):Promise

    4.使用

    以查询mysql为例子

    var { DatabaseManager, DbType } = require("hdb-mgr");
    DatabaseManager.useConfig({
      host: "localhost",
      port: 3306,
      user: "root",
      password: "xxx",
      dbname: "test"
    });
    var db = new DatabaseManager();
    db.findSync("user")
      .then(function(data) {
        console.log(data);
      })
      .catch(function(err) {
        console.log(err);
      });

    Install

    npm i huafua_dbmanager

    DownloadsWeekly Downloads

    1

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    335 kB

    Total Files

    23

    Last publish

    Collaborators

    • huafua