-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wangjian
committed
Mar 18, 2020
1 parent
9c5e4c3
commit c002d10
Showing
25 changed files
with
14,745 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,7 @@ | ||
# Logs | ||
node_modules | ||
.DS_Store | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
src/ | ||
node_modules/ | ||
build/ | ||
example/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# h-mysql | ||
|
||
* **作者**:浪子神剑 | ||
* **邮箱**:<[email protected]> | ||
* **网站**:[http://www.haizlin.com](http://www.haizlin.com) | ||
* **介绍**:一直以来很喜欢Thinkphp的数据操作风格,所以在nodejs上也封装了一个MYSQL数据库的常用操作,支持链式调用,实现语义化的数据库操作。 | ||
|
||
## 安装及引用 | ||
|
||
```javascript | ||
|
||
// npm安装 | ||
npm i h-mysql --save | ||
|
||
// yarn安装 | ||
yarn add h-mysql | ||
|
||
const hMysql = require('h-mysql'); | ||
``` | ||
|
||
## 初始化配置 | ||
```javascriipt | ||
const hMysql = new mysql({ | ||
host: '127.0.0.1', | ||
user: 'root', | ||
password: '', | ||
database: 'test-db', | ||
port: 3306, | ||
acquireTimeout: 1000, | ||
waitForConnections: true, //是否等待链接 | ||
connectionLimit: 10, // 连接池数 | ||
queueLimit: 0, // 排队限制 | ||
defaultSqlPre: '', | ||
isPool: true, | ||
isDebug: true | ||
}); | ||
const {error, result} = await hMysql.table('user') | ||
.where({ id: 100 }) | ||
.select() | ||
.execSql(); | ||
console.log(result); | ||
``` | ||
|
||
## 调用方式 | ||
> 规则:调用方法跟顺序无关 | ||
```javascript | ||
let hMysql = new hMysql(config) | ||
|
||
hMysql.table() | ||
.where() | ||
.limit() | ||
.select() | ||
.execSql() | ||
``` | ||
|
||
## [CURD操作](./docs/api.md) | ||
* 添加:[insert] [table] [data] | ||
* 查询:[select] [field] from [table] [alias] [where] [join] | ||
* 更新:[update] [table] set [data] [where] | ||
* 删除:[delete] from [table] [where] | ||
|
||
## [API 文档](./docs/api.md) | ||
* CURD操作 | ||
* [.select()]() ⇒ Promise | ||
* [.find()]() ⇒ Promise | ||
* [.update()]() ⇒ Promise | ||
* [.updateMany()]() ⇒ Promise | ||
* [.insert()]() ⇒ Promise | ||
* [.delete()]() ⇒ Promise | ||
* [.query(sql: string)]() ⇒ Promise | ||
|
||
* 链式方法 | ||
* [.table(tableName: string)]() ⇒ Mysql | ||
* [.alias(tableAlias: string)]()⇒ Mysql | ||
* [.field(opt: string | any[])]() ⇒ Mysql | ||
* [.where(opt: string | any[])]() ⇒ Mysql | ||
* [.limit(limit)]() ⇒ Mysql | ||
* [.page(pageSize, pageNum)]() ⇒ Mysql | ||
* [.data(data:object)]() ⇒ Mysql | ||
* [.order(order)]() ⇒ Mysql | ||
* [.join()]() ⇒ Mysql | ||
* [.union()]() ⇒ Mysql | ||
* [.count()]() ⇒ Promise | ||
* [.group(field)]() ⇒ Mysql | ||
* [.having(field)]() ⇒ Mysql | ||
* [.count(field)]() ⇒ Mysql | ||
* [.max(field)]() ⇒ Mysql | ||
* [.min(field)]() ⇒ Mysql | ||
* [.avg(field)]() ⇒ Mysql | ||
* [.sum(field)]() ⇒ Mysql | ||
* [.lock(field, step)]() ⇒ Promise | ||
* [.distinct(field, step)]() ⇒ Promise | ||
* [.comment(str:string)]() ⇒ Promise | ||
* [.execSql()]() ⇒ string | ||
|
||
## 迭代计划 | ||
- [ ] 完善API文档、架构文档 | ||
- [ ] 完善案例 | ||
- [ ] 批量插入、批量更新、批量删除 | ||
- [ ] 支持更复杂的链式操作 | ||
- [ ] 添加测试用例 | ||
- [ ] 重写异常处理方式 | ||
- [ ] 添加性能测试并添加每条语句执行的时间 | ||
- [ ] 添加安全测试,防注入 | ||
- [ ] 增加对数据库的操作(现在的功能都是针对表) | ||
- [ ] 考虑是不是要支持ORM | ||
|
||
|
||
## 版本更新 | ||
* v0.0.1 | ||
* 实现常用方法的链式调用,未经过测试,慎用到生产环境,待更新到1.0版本吧 | ||
|
||
## 贡献 | ||
|
||
## License | ||
[![MIT](http://api.haizlin.cn/api?mod=interview&ctr=issues&act=generateSVG&type=h-mysql)](https://github.com/haizlin/h-mysql/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const util = require("./util"); | ||
const baseConfig = require("./rollup.config"); | ||
|
||
module.exports = { | ||
...baseConfig, | ||
output: { | ||
file: util.resolve("dist/h-tools.js"), | ||
format: "cjs" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const banner = require('rollup-plugin-banner').default; | ||
const json = require('rollup-plugin-json'); | ||
const pkg = require('../package.json'); | ||
const util = require("./util"); | ||
const typescript = require("rollup-plugin-typescript"); | ||
const babel = require("rollup-plugin-babel"); | ||
const nodeResolve = require("rollup-plugin-node-resolve"); | ||
const commonjs = require("rollup-plugin-commonjs"); | ||
|
||
let year = new Date().getFullYear(), | ||
version = pkg.version; | ||
|
||
let bannerText = `h-mysql v${version} | ||
(c) 2018-${year} haizlin https://github.com/haizlin/h-mysql | ||
Licensed MIT | ||
Released on: February 1, 2018`; | ||
|
||
const extensions = [".js", ".ts", ".tsx"]; | ||
|
||
const babelOptions = { | ||
extensions, | ||
runtimeHelpers: true, | ||
presets: [ | ||
[ | ||
"@babel/env", | ||
{ | ||
modules: false, | ||
targets: { | ||
node: "12.9.1" | ||
} | ||
} | ||
] | ||
] | ||
}; | ||
|
||
const typescriptOptions = { | ||
strict: true, | ||
module: "ES6", | ||
target: "ESNext" | ||
}; | ||
|
||
module.exports = { | ||
input: util.resolve("src/index.ts"), | ||
plugins: [ | ||
typescript(typescriptOptions), | ||
nodeResolve({ extensions }), | ||
commonjs({ extensions, ignore: ["conditional-runtime-dependency"] }), | ||
babel(babelOptions), | ||
banner(bannerText), | ||
json() | ||
], | ||
external: ["schema-verify"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const util = require("./util"); | ||
const baseConfig = require("./rollup.config"); | ||
|
||
module.exports = { | ||
...baseConfig, | ||
output: { | ||
file: util.resolve("dist/h-mysql.js"), | ||
format: "cjs" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require("path"); | ||
|
||
const resolve = function(filePath) { | ||
return path.join(__dirname, "..", filePath); | ||
}; | ||
|
||
module.exports = { | ||
resolve | ||
}; |
Oops, something went wrong.