How to use the @nozbe/watermelondb/adapters/sqlite 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 RocketChat / Rocket.Chat.ReactNative / app / lib / database / index.js View on Github external
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 Nozbe / WatermelonDB / examples / native / index.js View on Github external
import { AppRegistry, NativeModules } from 'react-native'

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 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,