How to use the @nozbe/watermelondb.Database function in @nozbe/watermelondb

To help you get started, we’ve selected a few @nozbe/watermelondb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AliAllaf / firemelon / src / utils / schema.ts View on Github external
export default function newDatabase() {
    const adapter = new LokiJSAdapter({
        schema,
    });
    const database = new Database({
        actionsEnabled: true,
        adapter,
        // @ts-ignore
        modelClasses: [Todo, User],
    });

    return database;
}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / index.js View on Github external
import serversSchema from './schema/servers';
import appSchema from './schema/app';

import migrations from './model/migrations';

import { isIOS } from '../../utils/deviceInfo';

const appGroupPath = isIOS ? `${ RNFetchBlob.fs.syncPathAppGroup('group.ios.chat.rocket') }/` : '';

if (__DEV__ && isIOS) {
	console.log(appGroupPath);
}

class DB {
	databases = {
		serversDB: new Database({
			adapter: new SQLiteAdapter({
				dbName: `${ appGroupPath }default.db`,
				schema: serversSchema
			}),
			modelClasses: [Server, User],
			actionsEnabled: true
		})
	}

	get active() {
		return this.databases.activeDB;
	}

	get servers() {
		return this.databases.serversDB;
	}
github RocketChat / Rocket.Chat.ReactNative / app / lib / database / index.js View on Github external
setActiveDB(database = '') {
		const path = database.replace(/(^\w+:|^)\/\//, '');
		const dbName = `${ appGroupPath }${ path }.db`;

		const adapter = new SQLiteAdapter({
			dbName,
			schema: appSchema,
			migrations
		});

		this.databases.activeDB = new Database({
			adapter,
			modelClasses: [
				Subscription,
				Room,
				Message,
				Thread,
				ThreadMessage,
				CustomEmoji,
				FrequentlyUsedEmoji,
				Upload,
				Setting,
				Role,
				Permission,
				SlashCommand
			],
			actionsEnabled: true
github Nozbe / WatermelonDB / examples / native / index.js View on Github external
import { Database } from '@nozbe/watermelondb'
import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite'

import { mySchema } from './src/models/schema'
import Blog from './src/models/Blog'
import Post from './src/models/Post'
import Comment from './src/models/Comment'

import { createNavigation } from './src/components/helpers/Navigation'

const adapter = new SQLiteAdapter({
  dbName: 'WatermelonDemo',
  schema: mySchema,
})

const database = new Database({
  adapter,
  modelClasses: [Blog, Post, Comment],
  actionsEnabled: true,
})

const appStartedLaunchingAt = NativeModules.PerformancePlugin.appInitTimestamp
const timeToLaunch = new Date().getTime() - appStartedLaunchingAt

const Navigation = createNavigation({ database, timeToLaunch })

AppRegistry.registerComponent('App', () => Navigation)
github status-im / liquid-funding / src / db.js View on Github external
import schema from './model/schema'
import LpEvent from './model/lpEvents'
import VaultEvent from './model/vaultEvent'
import Profile from './model/profile'
import Pledge from './model/pledge'
import Delegate from './model/delegate'

const dbName = 'LiquidFunding'

const adapter = new LokiJSAdapter({
  dbName,
  schema,
})

const database = new Database({
  adapter,
  modelClasses: [
    LpEvent,
    VaultEvent,
    Profile,
    Pledge,
    Delegate
  ],
  actionsEnabled: true,
})

export default database
github Nozbe / WatermelonDB / examples / web / src / index.js View on Github external
import LokiJSAdapter from '@nozbe/watermelondb/adapters/lokijs'
import DatabaseProvider from '@nozbe/watermelondb/DatabaseProvider'

import { mySchema } from 'models/schema'
import Blog from 'models/Blog'
import Post from 'models/Post'
import Comment from 'models/Comment'

import Root from 'components/Root'

const adapter = new LokiJSAdapter({
  dbName: 'WatermelonDemo',
  schema: mySchema,
})

const database = new Database({
  adapter,
  modelClasses: [Blog, Post, Comment],
  actionsEnabled: true,
})

render(
  
    
  , document.getElementById('application')
)