add field generator fn
This commit is contained in:
parent
689ca5e287
commit
88cdc66593
|
@ -10,7 +10,6 @@ export const addEvent = async data => {
|
||||||
lpEvent.address = address
|
lpEvent.address = address
|
||||||
lpEvent.event = event
|
lpEvent.event = event
|
||||||
lpEvent.blockNumber = blockNumber
|
lpEvent.blockNumber = blockNumber
|
||||||
return lpEvent
|
|
||||||
})
|
})
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
|
@ -24,7 +23,6 @@ export const batchAddEvents = async events => {
|
||||||
lpEvent.address = address
|
lpEvent.address = address
|
||||||
lpEvent.event = event
|
lpEvent.event = event
|
||||||
lpEvent.blockNumber = blockNumber
|
lpEvent.blockNumber = blockNumber
|
||||||
return lpEvent
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
console.log({batch})
|
console.log({batch})
|
||||||
|
@ -34,7 +32,7 @@ export const batchAddEvents = async events => {
|
||||||
|
|
||||||
export const getLpEventById = async id => {
|
export const getLpEventById = async id => {
|
||||||
const event = await lpCollection.query(
|
const event = await lpCollection.query(
|
||||||
//Q.where('event_id', id)
|
Q.where('event_id', id)
|
||||||
).fetch()
|
).fetch()
|
||||||
console.log({event})
|
console.log({event})
|
||||||
return event
|
return event
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
import { Model } from '@nozbe/watermelondb'
|
import { Model } from '@nozbe/watermelondb'
|
||||||
import { action } from '@nozbe/watermelondb/decorators'
|
import { action } from '@nozbe/watermelondb/decorators'
|
||||||
|
import { fieldGenerator } from '../utils/db'
|
||||||
|
|
||||||
export default class LpEvent extends Model {
|
export default class LpEvent extends Model {
|
||||||
static table = 'lp_events'
|
constructor(...args) {
|
||||||
|
super(...args)
|
||||||
|
const field = fieldGenerator(this)
|
||||||
|
field('event_id', 'eventId')
|
||||||
|
field('address')
|
||||||
|
field('event')
|
||||||
|
field('block_number', 'blockNumber')
|
||||||
|
}
|
||||||
|
|
||||||
@field('event_id') eventId
|
static table = 'lp_events'
|
||||||
@field('address') address
|
|
||||||
@field('event') event
|
|
||||||
@field('block_number') blockNumber
|
|
||||||
|
|
||||||
@action async addEvent(data) {
|
@action async addEvent(data) {
|
||||||
return await this.create(lpEvent => {
|
return await this.create(lpEvent => {
|
||||||
|
@ -18,5 +23,4 @@ export default class LpEvent extends Model {
|
||||||
lpEvent.blockNumber = blockNumber
|
lpEvent.blockNumber = blockNumber
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
export const fieldGenerator = self => (column, name) => {
|
||||||
|
Object.defineProperty(self, name || column, {
|
||||||
|
get() { return self._getRaw(column) },
|
||||||
|
set(value) { self._setRaw(column, value) },
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue