Skip to content

Commit 992a94a

Browse files
committed
Simplify code
1 parent eb89653 commit 992a94a

File tree

1 file changed

+50
-61
lines changed

1 file changed

+50
-61
lines changed

src/index.js

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -322,29 +322,27 @@ utils.addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
322322
},
323323

324324
_count (mapper, query, opts) {
325-
const self = this
326325
opts || (opts = {})
327326
query || (query = {})
328327

329-
return self.filterSequence(self.selectTable(mapper, opts), query)
328+
return this.filterSequence(this.selectTable(mapper, opts), query)
330329
.count()
331-
.run(self.getOpt('runOpts', opts)).then(function (count) {
332-
return [count, {}]
333-
})
330+
.run(this.getOpt('runOpts', opts))
331+
.then((count) => [count, {}])
334332
},
335333

336334
_create (mapper, props, opts) {
337-
const self = this
338335
props || (props = {})
339336
opts || (opts = {})
340337

341-
const insertOpts = self.getOpt('insertOpts', opts)
338+
const insertOpts = this.getOpt('insertOpts', opts)
342339
insertOpts.returnChanges = true
343340

344-
return self.selectTable(mapper, opts)
341+
return this.selectTable(mapper, opts)
345342
.insert(props, insertOpts)
346-
.run(self.getOpt('runOpts', opts)).then(function (cursor) {
347-
self._handleErrors(cursor)
343+
.run(this.getOpt('runOpts', opts))
344+
.then((cursor) => {
345+
this._handleErrors(cursor)
348346
let record
349347
if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {
350348
record = cursor.changes[0].new_val
@@ -354,105 +352,96 @@ utils.addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
354352
},
355353

356354
_createMany (mapper, props, opts) {
357-
const self = this
358355
props || (props = {})
359356
opts || (opts = {})
360357

361-
const insertOpts = self.getOpt('insertOpts', opts)
358+
const insertOpts = this.getOpt('insertOpts', opts)
362359
insertOpts.returnChanges = true
363360

364-
return self.selectTable(mapper, opts)
361+
return this.selectTable(mapper, opts)
365362
.insert(props, insertOpts)
366-
.run(self.getOpt('runOpts', opts)).then(function (cursor) {
367-
self._handleErrors(cursor)
363+
.run(this.getOpt('runOpts', opts))
364+
.then((cursor) => {
365+
this._handleErrors(cursor)
368366
let records = []
369367
if (cursor && cursor.changes && cursor.changes.length && cursor.changes) {
370-
records = cursor.changes.map(function (change) {
371-
return change.new_val
372-
})
368+
records = cursor.changes.map((change) => change.new_val)
373369
}
374370
return [records, cursor]
375371
})
376372
},
377373

378374
_destroy (mapper, id, opts) {
379-
const self = this
380375
opts || (opts = {})
381376

382-
return self.selectTable(mapper, opts)
377+
return this.selectTable(mapper, opts)
383378
.get(id)
384-
.delete(self.getOpt('deleteOpts', opts))
385-
.run(self.getOpt('runOpts', opts)).then(function (cursor) {
386-
self._handleErrors(cursor)
379+
.delete(this.getOpt('deleteOpts', opts))
380+
.run(this.getOpt('runOpts', opts))
381+
.then((cursor) => {
382+
this._handleErrors(cursor)
387383
return [undefined, cursor]
388384
})
389385
},
390386

391387
_destroyAll (mapper, query, opts) {
392-
const self = this
393388
query || (query = {})
394389
opts || (opts = {})
395390

396-
return self
397-
.filterSequence(self.selectTable(mapper, opts), query)
398-
.delete(self.getOpt('deleteOpts', opts))
399-
.run(self.getOpt('runOpts', opts)).then(function (cursor) {
400-
self._handleErrors(cursor)
391+
return this.filterSequence(this.selectTable(mapper, opts), query)
392+
.delete(this.getOpt('deleteOpts', opts))
393+
.run(this.getOpt('runOpts', opts))
394+
.then((cursor) => {
395+
this._handleErrors(cursor)
401396
return [undefined, cursor]
402397
})
403398
},
404399

405400
_find (mapper, id, opts) {
406-
const self = this
407401
opts || (opts = {})
408402

409-
return self.selectTable(mapper, opts)
403+
return this.selectTable(mapper, opts)
410404
.get(id)
411-
.run(self.getOpt('runOpts', opts)).then(function (record) {
412-
return [record, {}]
413-
})
405+
.run(this.getOpt('runOpts', opts))
406+
.then((record) => [record, {}])
414407
},
415408

416409
_findAll (mapper, query, opts) {
417-
const self = this
418410
opts || (opts = {})
419411
query || (query = {})
420412

421-
return self.filterSequence(self.selectTable(mapper, opts), query)
422-
.run(self.getOpt('runOpts', opts)).then(function (records) {
423-
return [records, {}]
424-
})
413+
return this.filterSequence(this.selectTable(mapper, opts), query)
414+
.run(this.getOpt('runOpts', opts))
415+
.then((records) => [records, {}])
425416
},
426417

427418
_sum (mapper, field, query, opts) {
428-
const self = this
429419
if (!utils.isString(field)) {
430420
throw new Error('field must be a string!')
431421
}
432422
opts || (opts = {})
433423
query || (query = {})
434424

435-
return self.filterSequence(self.selectTable(mapper, opts), query)
425+
return this.filterSequence(this.selectTable(mapper, opts), query)
436426
.sum(field)
437-
.run(self.getOpt('runOpts', opts)).then(function (sum) {
438-
return [sum, {}]
439-
})
427+
.run(this.getOpt('runOpts', opts))
428+
.then((sum) => [sum, {}])
440429
},
441430

442431
_update (mapper, id, props, opts) {
443-
const self = this
444432
props || (props = {})
445433
opts || (opts = {})
446434

447-
const updateOpts = self.getOpt('updateOpts', opts)
435+
const updateOpts = this.getOpt('updateOpts', opts)
448436
updateOpts.returnChanges = true
449437

450-
return self.selectTable(mapper, opts)
438+
return this.selectTable(mapper, opts)
451439
.get(id)
452440
.update(props, updateOpts)
453-
.run(self.getOpt('runOpts', opts)).then(function (cursor) {
441+
.run(this.getOpt('runOpts', opts))
442+
.then((cursor) => {
454443
let record
455-
self._handleErrors(cursor)
444+
this._handleErrors(cursor)
456445
if (cursor && cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {
457446
record = cursor.changes[0].new_val
458447
} else {
@@ -463,42 +452,42 @@ utils.addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
463452
},
464453

465454
_updateAll (mapper, props, query, opts) {
466-
const self = this
467455
props || (props = {})
468456
query || (query = {})
469457
opts || (opts = {})
470458

471-
const updateOpts = self.getOpt('updateOpts', opts)
459+
const updateOpts = this.getOpt('updateOpts', opts)
472460
updateOpts.returnChanges = true
473461

474-
return self.filterSequence(self.selectTable(mapper, opts), query)
462+
return this.filterSequence(this.selectTable(mapper, opts), query)
475463
.update(props, updateOpts)
476-
.run(self.getOpt('runOpts', opts)).then(function (cursor) {
464+
.run(this.getOpt('runOpts', opts))
465+
.then((cursor) => {
477466
let records = []
478-
self._handleErrors(cursor)
467+
this._handleErrors(cursor)
479468
if (cursor && cursor.changes && cursor.changes.length) {
480-
records = cursor.changes.map(function (change) { return change.new_val })
469+
records = cursor.changes.map((change) => change.new_val)
481470
}
482471
return [records, cursor]
483472
})
484473
},
485474

486475
_updateMany (mapper, records, opts) {
487-
const self = this
488476
records || (records = [])
489477
opts || (opts = {})
490478

491-
const insertOpts = self.getOpt('insertOpts', opts)
479+
const insertOpts = this.getOpt('insertOpts', opts)
492480
insertOpts.returnChanges = true
493481
insertOpts.conflict = 'update'
494482

495-
return self.selectTable(mapper, opts)
483+
return this.selectTable(mapper, opts)
496484
.insert(records, insertOpts)
497-
.run(self.getOpt('runOpts', opts)).then(function (cursor) {
485+
.run(this.getOpt('runOpts', opts))
486+
.then((cursor) => {
498487
records = []
499-
self._handleErrors(cursor)
488+
this._handleErrors(cursor)
500489
if (cursor && cursor.changes && cursor.changes.length) {
501-
records = cursor.changes.map(function (change) { return change.new_val })
490+
records = cursor.changes.map((change) => change.new_val)
502491
}
503492
return [records, cursor]
504493
})

0 commit comments

Comments
 (0)