add profiles model + schema

This commit is contained in:
Barry Gitarts 2019-01-16 15:50:49 -05:00
parent 88cdc66593
commit 22526b59ce
3 changed files with 70 additions and 0 deletions

37
app/actions/profiles.js Normal file
View File

@ -0,0 +1,37 @@
import { Q } from '@nozbe/watermelondb'
import database from '../db'
const profilesCollection = database.collections.get('profiles')
export const addProfile = async data => {
await database.action(async () => {
const res = await profilesCollection.create(profile => {
const { addr, canceled, commitTime, type, name, url, idProfile } = data
//TODO add assignemnts
})
return res
})
}
export const batchAddProfiles = async profiles => {
const batch = profiles.map(data => {
return profilesCollection.prepareCreate(profile => {
const { addr, canceled, commitTime, type, name, url, idProfile } = data
profile.addr = addr
profile.canceled = canceled
profile.commitTime = commitTime
profile.type = type
profile.name = name
profile.url = url
profile.idProfile = idProfile
})
})
console.log({batch})
return await database.action(async () => await database.batch(...batch))
}
export const getProfileById = async id => {
const event = await profilesCollection.query(
Q.where('id_profile', id)
).fetch()
return event
}

20
app/model/profiles.js Normal file
View File

@ -0,0 +1,20 @@
import { Model } from '@nozbe/watermelondb'
import { fieldGenerator } from '../utils/db'
export default class Profiles extends Model {
constructor(...args) {
super(...args)
const field = fieldGenerator(this)
field('addr')
field('canceled')
field('commit_time', 'commitTime')
field('type')
field('name')
field('url')
field('id_profile', 'idProfile')
}
static table = 'profiles'
}

View File

@ -11,6 +11,19 @@ export default appSchema({
{ name: 'event_id', type: 'string' },
{ name: 'block_number', type: 'number', isIndexed: true },
]
}),
tableSchema({
name: 'profiles',
columns: [
{ name: 'addr', type: 'string' },
{ name: 'canceled', type: 'boolean' },
{ name: 'commit_time', type: 'number' },
{ name: 'type', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'url', type: 'string' },
{ name: 'id_profile', type: 'number' }
]
})
]
})