parent
1af8c64323
commit
e45183ceb8
|
@ -1,3 +1,7 @@
|
|||
# 3.0.9 / 2019-09-23
|
||||
* 优化创建数据库/表时的默认配置顶;
|
||||
* 优化字段的默认值0的判断
|
||||
|
||||
# 3.0.8 / 2019-09-19
|
||||
* 修复tableCreate在没有索引时建表失败的bug
|
||||
* 更新文档
|
||||
|
|
|
@ -108,7 +108,7 @@ db.tableList().then(list => {
|
|||
### dbCreate(name, options)
|
||||
|
||||
* name `<String>` [必传], 数据库名字
|
||||
* options `<Object>`, [必传], 数据库的配置
|
||||
* options `<Object>`, [选传], 数据库的配置
|
||||
- charset `<String>` 默认 utf8mb4
|
||||
|
||||
|
||||
|
@ -133,7 +133,7 @@ db.dbCreate('foo', { charset: 'utf8' }) // 默认是utf8mb4
|
|||
- unique `<Boolean>` 是否为 唯一索引
|
||||
- default `<Any>` 设置默认值
|
||||
- update `<Boolean>` 是否自动更新(只有 datetime & timestamp 可以设)
|
||||
* options `<Object>`, [必传], 表的配置
|
||||
* options `<Object>`, [选传], 表的配置
|
||||
- charset `<String>` 默认 utf8mb4
|
||||
- engine `<String>` 默认 InnoDB
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ class Api {
|
|||
}
|
||||
|
||||
// 创建新的数据库
|
||||
dbCreate(name, { charset = 'utf8mb4' }) {
|
||||
dbCreate(name, { charset = 'utf8mb4' } = {}) {
|
||||
if (!name) {
|
||||
return Promise.reject('Empty database name.')
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class Api {
|
|||
}
|
||||
|
||||
// 创建新的表,
|
||||
tableCreate(name, fields, { charset = 'utf8mb4', engine = 'InnoDB' }) {
|
||||
tableCreate(name, fields, { charset = 'utf8mb4', engine = 'InnoDB' } = {}) {
|
||||
if (!name) {
|
||||
return Promise.reject('Empty database name.')
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ class Method {
|
|||
* sql: .filter('name like "foo%" and age > 18')
|
||||
* func: .filter(function(){return 'name = "xiaoming"'})
|
||||
* obj: .filter({
|
||||
* name: {$like: 'foo%'}
|
||||
* age: {$gt: 18}
|
||||
* })
|
||||
* name: {$like: 'foo%'}
|
||||
* age: {$gt: 18}
|
||||
* })
|
||||
* obj形式的过滤, 支持多种多样, 详细请看Readme介绍
|
||||
*/
|
||||
filter(val) {
|
||||
|
@ -406,9 +406,7 @@ class Method {
|
|||
return this.connect().then(conn => {
|
||||
const defer = Promise.defer()
|
||||
|
||||
let sql = `ALTER TABLE ${
|
||||
this.cache.table
|
||||
} ADD ${unique} INDEX \`${name}\` (${opt.field})`
|
||||
let sql = `ALTER TABLE ${this.cache.table} ADD ${unique} INDEX \`${name}\` (${opt.field})`
|
||||
|
||||
conn.query(sql, (err, result) => {
|
||||
conn.release()
|
||||
|
|
|
@ -237,13 +237,14 @@ const parser = {
|
|||
}
|
||||
let notnull = it.notnull ? 'NOT NULL' : 'NULL'
|
||||
|
||||
if (/CHAR/.test(it.type)) {
|
||||
if (~it.type.indexOf('CHAR')) {
|
||||
it.default = it.default ? escape(it.default) : ''
|
||||
}
|
||||
|
||||
// 这几种类型,不允许设置默认值
|
||||
if (['TEXT', 'BLOB', 'JSON', 'GEOMETRY'].includes(it.type)) {
|
||||
notnull = 'NULL'
|
||||
delete it.default
|
||||
}
|
||||
|
||||
// 这2种类型,如果设置了自动更新时间戳, 则默认值自动改为当前时间戳
|
||||
|
@ -257,10 +258,12 @@ const parser = {
|
|||
// 这3种时间类型,不允许设置默认值为 当前时间戳
|
||||
if (['TIME', 'DATE', 'YEAR'].includes(it.type)) {
|
||||
if (it.default.toUpperCase() === 'CURRENT_TIMESTAMP') {
|
||||
it.default = ''
|
||||
delete it.default
|
||||
}
|
||||
}
|
||||
defaultVal = it.default ? `DEFAULT ${it.default}` : ''
|
||||
if (it.default || it.default === 0) {
|
||||
defaultVal = 'DEFAULT ' + it.default
|
||||
}
|
||||
|
||||
// 非主键下, 设置了unique & index时,都为索引
|
||||
if (!it.primary) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mysqli",
|
||||
"version": "3.0.8",
|
||||
"version": "3.0.9",
|
||||
"description": "MySQL tool",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
|
Loading…
Reference in New Issue