From 22526b59ce1f0f3890504d23bdb5a437d1d12f71 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Wed, 16 Jan 2019 15:50:49 -0500 Subject: [PATCH] add profiles model + schema --- app/actions/profiles.js | 37 +++++++++++++++++++++++++++++++++++++ app/model/profiles.js | 20 ++++++++++++++++++++ app/model/schema.js | 13 +++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 app/actions/profiles.js create mode 100644 app/model/profiles.js diff --git a/app/actions/profiles.js b/app/actions/profiles.js new file mode 100644 index 0000000..b19dffe --- /dev/null +++ b/app/actions/profiles.js @@ -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 +} diff --git a/app/model/profiles.js b/app/model/profiles.js new file mode 100644 index 0000000..cfc34f5 --- /dev/null +++ b/app/model/profiles.js @@ -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' + +} + diff --git a/app/model/schema.js b/app/model/schema.js index 4d51b68..b9109e3 100644 --- a/app/model/schema.js +++ b/app/model/schema.js @@ -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' } + ] + }) ] })