From 4d79480e72acd13c68d88567eb96f6e3ee842833 Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 23 Jul 2024 18:54:00 +0800 Subject: [PATCH] update --- index.js | 3 +-- lib/api.js | 1 - lib/method.js | 13 ++++++++++++- lib/utils.js | 15 ++++++--------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index d87b6cd..93a18bf 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ class Mysqli { host, port, user, - charset, + charset = 'utf8mb4', passwd: password, db: database, timezone, @@ -39,7 +39,6 @@ class Mysqli { let name = i < 1 ? 'MASTER' : 'SLAVE' + i let collate - charset = charset || 'utf8mb4' collate = charset + (charset === 'utf8mb4' ? '_0900_ai_ci' : '_general_ci') diff --git a/lib/api.js b/lib/api.js index 9c85919..f573301 100644 --- a/lib/api.js +++ b/lib/api.js @@ -79,7 +79,6 @@ class Api { if (!this.db && db) { return Promise.reject('No database selected.') } - let defer = Promise.defer() return this.query(`DROP DATABASE IF EXISTS ${db || this.db}`) } diff --git a/lib/method.js b/lib/method.js index cba9511..93d30e4 100644 --- a/lib/method.js +++ b/lib/method.js @@ -128,7 +128,18 @@ class Method { } } - let { table, leftJoin, rightJoin, join, filter, fields, sort, skip, size, limit } = this.cache + let { + table, + leftJoin, + rightJoin, + join, + filter, + fields, + sort, + skip, + size, + limit + } = this.cache // 没有使用 slice方法的前提下, 通过skip/limit补全 if (!limit) { diff --git a/lib/utils.js b/lib/utils.js index 13a217a..13541e7 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -8,10 +8,7 @@ const { escape } = require('mysql') function hideProperty(host, name, value) { Object.defineProperty(host, name, { - value: value, - writable: true, - enumerable: false, - configurable: true + value: value }) } @@ -19,11 +16,9 @@ function getType(val) { if (val === null) { return String(val) } - return Object.prototype.toString - .call(val) - .slice(8, -1) - .toLowerCase() + return Object.prototype.toString.call(val).slice(8, -1).toLowerCase() } + function parse$or(arr) { let sql = '' for (let it of arr) { @@ -299,7 +294,9 @@ class SqlErr { hideProperty(this, 'stack', msg) console.error( line + - `\n[${new Date().format('Y/m/d_H:i:s')}][Last Query SQL]: ${sql}\nQuery ${msg}\n` + + `\n[${new Date().format( + 'Y/m/d_H:i:s' + )}][Last Query SQL]: ${sql}\nQuery ${msg}\n` + line ) }