Skip to content

Commit

Permalink
feat: format arrowParens (#15)
Browse files Browse the repository at this point in the history
* feat: upgrade coa-redis coa-echo

* feat: format arrowParens
  • Loading branch information
adaex authored Apr 28, 2022
1 parent 520a50d commit 6964ee2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"printWidth": 160,
"semi": false,
"singleQuote": true
"singleQuote": true,
"arrowParens": "avoid"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "NODE_PATH=run node dist/test",
"lint": "eslint .",
"prettier": "prettier -w .",
"sync": "curl -X PUT 'https://npm.taobao.org/sync/coa-mysql?sync_upstream=true'"
"sync": "curl -X PUT 'https://npmmirror.com/sync/coa-mysql?sync_upstream=true'"
},
"dependencies": {
"coa-echo": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Knex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Knex.QueryBuilder.extend('search', function (columns: string[], value: string) {
const length = columns.length
value &&
length &&
this.where((qb) => {
this.where(qb => {
const search = '%' + value + '%'
if (length >= 1) qb.where(columns[0], 'like', search)
if (length >= 2) for (let i = 1; i < length; i++) qb.orWhere(columns[i], 'like', search)
Expand Down
8 changes: 4 additions & 4 deletions src/services/MysqlCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
}

async mGetByIds(ids: string[], pick = this.pick, trx?: CoaMysql.Transaction, ms = this.ms, force = false) {
const result = await this.redisCache.mWarp(this.getCacheNsp('id'), ids, async (ids) => await super.mGetByIds(ids, this.columns, trx), ms, force)
const result = await this.redisCache.mWarp(this.getCacheNsp('id'), ids, async ids => await super.mGetByIds(ids, this.columns, trx), ms, force)
_.forEach(result, (v, k) => {
result[k] = this.pickResult(v, pick)
})
Expand Down Expand Up @@ -114,7 +114,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {

protected async mGetCountBy(field: string, ids: string[], trx?: CoaMysql.Transaction) {
const cacheNsp = this.getCacheNsp('count', field)
return await this.redisCache.mWarp(cacheNsp, ids, async (ids) => {
return await this.redisCache.mWarp(cacheNsp, ids, async ids => {
const rows = (await this.table(trx).select({ id: field }).count({ count: this.key }).whereIn(field, ids).groupBy(field)) as any[]
const result: CoaMysql.Dic<number> = {}
_.forEach(rows, ({ id, count }) => (result[id] = count))
Expand Down Expand Up @@ -145,7 +145,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
let has = true
const resultList = [] as Array<CoaMysql.SafePartial<Scheme>>
if (data) {
has = _.some(this.cachesFields, (i) => (data as any)[i] !== undefined)
has = _.some(this.cachesFields, i => (data as any)[i] !== undefined)
resultList.push(data)
}
if (has) {
Expand All @@ -161,7 +161,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
deleteIds.push([this.getCacheNsp('data'), []])
_.forEach(this.caches, (items, name) => {
// name可能为index,count,或自定义
items.forEach((item) => {
items.forEach(item => {
const keys = item.split(/[:,]/)
const key = keys[0]
const ids = [] as string[]
Expand Down
16 changes: 8 additions & 8 deletions src/services/MysqlNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ export class MysqlNative<Scheme> {
// 处理caches
this.caches = _.defaults(option.caches, { index: [], count: [] })
// 将需要用到缓存的字段单独记录为一个数组,方便判断是否需要处理缓存
_.forEach(this.caches, (items) =>
items.forEach((item) => {
_.forEach(this.caches, items =>
items.forEach(item => {
const field = item.split(/[:,]/)[0]
!this.cachesFields.includes(field) && this.cachesFields.push(field)
})
)
// 处理pick unpick
this.pick = option.pick || []
const unpick = option.unpick || []
unpick.forEach((u) => delete (option.scheme as any)[u])
unpick.forEach(u => delete (option.scheme as any)[u])
// 处理columns
_.forEach(this.scheme, (v, k: string) => {
if (v && typeof v === 'object') this.jsons.push(k)
Expand Down Expand Up @@ -159,7 +159,7 @@ export class MysqlNative<Scheme> {
const key = v[this.key] as string
result[key] = this.result(v, pick) as any
})
ids.forEach((id) => {
ids.forEach(id => {
if (!result.hasOwnProperty(id)) result[id] = null as any
})
return result
Expand Down Expand Up @@ -265,12 +265,12 @@ export class MysqlNative<Scheme> {
protected result(data: any, pick: string[]) {
if (data === null || data === undefined) return null
// 处理json
this.jsons.forEach((k) => {
this.jsons.forEach(k => {
if (data[k]) data[k] = JSON.parse(data[k])
})
// 处理默认值
const result = {} as any
pick.forEach((k) => {
pick.forEach(k => {
result[k] = data.hasOwnProperty(k) ? data[k] : this.scheme[k]
})
return result as Scheme
Expand All @@ -281,10 +281,10 @@ export class MysqlNative<Scheme> {
// 当为insert的时候填满数据
insert && _.defaults(data, this.scheme)
// 处理json
this.jsons.forEach((k) => {
this.jsons.forEach(k => {
if (typeof data[k] === 'object') data[k] = JSON.stringify(data[k])
})
this.virtual.forEach((k) => {
this.virtual.forEach(k => {
delete data[k]
})
return data
Expand Down
4 changes: 2 additions & 2 deletions src/test/test_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default new (class {
async testUuid() {
const workers = _.times(
100,
async (i) =>
await new Promise<void>(async (resolve) => {
async i =>
await new Promise<void>(async resolve => {
await $.timeout(_.random(1, 10))
const id = await cMysql.uuid.saltId()
console.log(i, id)
Expand Down

0 comments on commit 6964ee2

Please sign in to comment.