Skip to content

Commit 6964ee2

Browse files
authored
feat: format arrowParens (#15)
* feat: upgrade coa-redis coa-echo * feat: format arrowParens
1 parent 520a50d commit 6964ee2

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

.prettierrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"printWidth": 160,
33
"semi": false,
4-
"singleQuote": true
4+
"singleQuote": true,
5+
"arrowParens": "avoid"
56
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test": "NODE_PATH=run node dist/test",
2121
"lint": "eslint .",
2222
"prettier": "prettier -w .",
23-
"sync": "curl -X PUT 'https://npm.taobao.org/sync/coa-mysql?sync_upstream=true'"
23+
"sync": "curl -X PUT 'https://npmmirror.com/sync/coa-mysql?sync_upstream=true'"
2424
},
2525
"dependencies": {
2626
"coa-echo": "^1.2.1",

src/libs/Knex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Knex.QueryBuilder.extend('search', function (columns: string[], value: string) {
2020
const length = columns.length
2121
value &&
2222
length &&
23-
this.where((qb) => {
23+
this.where(qb => {
2424
const search = '%' + value + '%'
2525
if (length >= 1) qb.where(columns[0], 'like', search)
2626
if (length >= 2) for (let i = 1; i < length; i++) qb.orWhere(columns[i], 'like', search)

src/services/MysqlCache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
7575
}
7676

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

115115
protected async mGetCountBy(field: string, ids: string[], trx?: CoaMysql.Transaction) {
116116
const cacheNsp = this.getCacheNsp('count', field)
117-
return await this.redisCache.mWarp(cacheNsp, ids, async (ids) => {
117+
return await this.redisCache.mWarp(cacheNsp, ids, async ids => {
118118
const rows = (await this.table(trx).select({ id: field }).count({ count: this.key }).whereIn(field, ids).groupBy(field)) as any[]
119119
const result: CoaMysql.Dic<number> = {}
120120
_.forEach(rows, ({ id, count }) => (result[id] = count))
@@ -145,7 +145,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
145145
let has = true
146146
const resultList = [] as Array<CoaMysql.SafePartial<Scheme>>
147147
if (data) {
148-
has = _.some(this.cachesFields, (i) => (data as any)[i] !== undefined)
148+
has = _.some(this.cachesFields, i => (data as any)[i] !== undefined)
149149
resultList.push(data)
150150
}
151151
if (has) {
@@ -161,7 +161,7 @@ export class MysqlCache<Scheme> extends MysqlNative<Scheme> {
161161
deleteIds.push([this.getCacheNsp('data'), []])
162162
_.forEach(this.caches, (items, name) => {
163163
// name可能为index,count,或自定义
164-
items.forEach((item) => {
164+
items.forEach(item => {
165165
const keys = item.split(/[:,]/)
166166
const key = keys[0]
167167
const ids = [] as string[]

src/services/MysqlNative.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ export class MysqlNative<Scheme> {
4444
// 处理caches
4545
this.caches = _.defaults(option.caches, { index: [], count: [] })
4646
// 将需要用到缓存的字段单独记录为一个数组,方便判断是否需要处理缓存
47-
_.forEach(this.caches, (items) =>
48-
items.forEach((item) => {
47+
_.forEach(this.caches, items =>
48+
items.forEach(item => {
4949
const field = item.split(/[:,]/)[0]
5050
!this.cachesFields.includes(field) && this.cachesFields.push(field)
5151
})
5252
)
5353
// 处理pick unpick
5454
this.pick = option.pick || []
5555
const unpick = option.unpick || []
56-
unpick.forEach((u) => delete (option.scheme as any)[u])
56+
unpick.forEach(u => delete (option.scheme as any)[u])
5757
// 处理columns
5858
_.forEach(this.scheme, (v, k: string) => {
5959
if (v && typeof v === 'object') this.jsons.push(k)
@@ -159,7 +159,7 @@ export class MysqlNative<Scheme> {
159159
const key = v[this.key] as string
160160
result[key] = this.result(v, pick) as any
161161
})
162-
ids.forEach((id) => {
162+
ids.forEach(id => {
163163
if (!result.hasOwnProperty(id)) result[id] = null as any
164164
})
165165
return result
@@ -265,12 +265,12 @@ export class MysqlNative<Scheme> {
265265
protected result(data: any, pick: string[]) {
266266
if (data === null || data === undefined) return null
267267
// 处理json
268-
this.jsons.forEach((k) => {
268+
this.jsons.forEach(k => {
269269
if (data[k]) data[k] = JSON.parse(data[k])
270270
})
271271
// 处理默认值
272272
const result = {} as any
273-
pick.forEach((k) => {
273+
pick.forEach(k => {
274274
result[k] = data.hasOwnProperty(k) ? data[k] : this.scheme[k]
275275
})
276276
return result as Scheme
@@ -281,10 +281,10 @@ export class MysqlNative<Scheme> {
281281
// 当为insert的时候填满数据
282282
insert && _.defaults(data, this.scheme)
283283
// 处理json
284-
this.jsons.forEach((k) => {
284+
this.jsons.forEach(k => {
285285
if (typeof data[k] === 'object') data[k] = JSON.stringify(data[k])
286286
})
287-
this.virtual.forEach((k) => {
287+
this.virtual.forEach(k => {
288288
delete data[k]
289289
})
290290
return data

src/test/test_uuid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default new (class {
99
async testUuid() {
1010
const workers = _.times(
1111
100,
12-
async (i) =>
13-
await new Promise<void>(async (resolve) => {
12+
async i =>
13+
await new Promise<void>(async resolve => {
1414
await $.timeout(_.random(1, 10))
1515
const id = await cMysql.uuid.saltId()
1616
console.log(i, id)

0 commit comments

Comments
 (0)