Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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)
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,