1.0.1 • Published 3 years ago

pg-mysql v1.0.1

Weekly downloads
5
License
ISC
Repository
-
Last release
3 years ago

node环境下连接mysql

​ 前端练习node后端框架时,经常需要封装数据库连接方式,本插件封装了mysql数据库的连接方式;

安装

​ 使用npm:

npm i pg-mysql

使用方式

const Db = require('pg-mysql');

/* 数据库配置 */
const dbconfig = {
  host: 'localhost',
  user: 'root',
  password: '123456',
  database: 'test'
}

/* 应用数据库配置配置 */
const db = new Db(dbconfig);

/**
 * query连接并查询
 * @params: String sql语句
 * @params: Array sql语句参数
 * @return: Promise 返回的查询结果为Promise对象
 */
db.query("select * from 表格 where id=?", [0]);

/**
 * 关闭数据库连接
 */
db.close();

注意:

​ 以上便是该插件的使用方式,插件内部封装连接mysql数据库的构造函数,实现基本的连接、查询和关闭功能,更多功能后续持续更新……

1.0.1

3 years ago

1.0.0

3 years ago