Skip to content

Commit

Permalink
added conditional db connection for device and browser
Browse files Browse the repository at this point in the history
  • Loading branch information
nextlevelshit committed Feb 25, 2018
1 parent 755d118 commit 7b17a13
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 77 deletions.
4 changes: 2 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
<splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
<icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
</platform>
<engine name="android" spec="^6.3.0" />
<engine name="android" spec="^6.4.0" />
<engine name="ios" spec="^4.5.0" />
<plugin name="cordova-plugin-device" spec="^1.1.4" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.2.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
<plugin name="cordova-sqlite-storage" spec="^2.0.4" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<plugin name="cordova-plugin-device" spec="^1.1.7" />
</widget>
124 changes: 62 additions & 62 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
{
"name": "ionic-example",
"version": "1.0.0",
"author": "Daniel Lang",
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"config": {
"ionic_webpack": "./config/webpack.config.js"
},
"dependencies": {
"@angular/common": "4.4.3",
"@angular/compiler": "4.4.3",
"@angular/compiler-cli": "4.4.3",
"@angular/core": "4.4.3",
"@angular/forms": "4.4.3",
"@angular/http": "4.4.3",
"@angular/platform-browser": "4.4.3",
"@angular/platform-browser-dynamic": "4.4.3",
"@ionic-native/core": "4.3.0",
"@ionic-native/splash-screen": "4.3.0",
"@ionic-native/status-bar": "4.3.0",
"@ionic/storage": "2.0.1",
"cordova-android": "^6.3.0",
"cordova-ios": "^4.5.0",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.2",
"cordova-plugin-whitelist": "^1.3.1",
"cordova-sqlite-storage": "^2.0.4",
"ionic-angular": "3.7.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "5.4.3",
"sw-toolbox": "3.6.0",
"typeorm": "0.1.6",
"zone.js": "0.8.17"
},
"devDependencies": {
"@ionic/app-scripts": "^3.0.0",
"@types/node": "^8.0.31",
"sql.js": "^0.5.0",
"typescript": "2.3.4"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-sqlite-storage": {}
"name": "ionic-example",
"version": "1.0.0",
"author": "Daniel Lang",
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"platforms": [
"android",
"ios"
]
}
}
"config": {
"ionic_webpack": "./config/webpack.config.js"
},
"dependencies": {
"@angular/common": "4.4.3",
"@angular/compiler": "4.4.3",
"@angular/compiler-cli": "4.4.3",
"@angular/core": "4.4.3",
"@angular/forms": "4.4.3",
"@angular/http": "4.4.3",
"@angular/platform-browser": "4.4.3",
"@angular/platform-browser-dynamic": "4.4.3",
"@ionic-native/core": "4.3.0",
"@ionic-native/splash-screen": "4.3.0",
"@ionic-native/status-bar": "4.3.0",
"@ionic/storage": "2.0.1",
"cordova-android": "^6.4.0",
"cordova-ios": "^4.5.0",
"cordova-plugin-device": "^1.1.7",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.2",
"cordova-plugin-whitelist": "^1.3.1",
"cordova-sqlite-storage": "^2.0.4",
"ionic-angular": "3.7.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "5.4.3",
"sw-toolbox": "3.6.0",
"typeorm": "0.1.6",
"zone.js": "0.8.17"
},
"devDependencies": {
"@ionic/app-scripts": "^3.0.0",
"@types/node": "^8.0.31",
"sql.js": "^0.5.0",
"typescript": "2.3.4"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-sqlite-storage": {}
},
"platforms": [
"android",
"ios"
]
}
}
45 changes: 32 additions & 13 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Post } from '../entities/post';
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any;
rootPage: any;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(async () => {
Expand All @@ -23,18 +23,37 @@ export class MyApp {
statusBar.styleDefault();
splashScreen.hide();

await createConnection({
type: 'cordova',
database: 'test',
location: 'default',
logging: ['error', 'query', 'schema'],
synchronize: true,
entities: [
Author,
Category,
Post
]
});
// Depending on the machine the app is running on, configure
// different database connections
if(platform.is('cordova')) {
// Running on device or emulator
await createConnection({
type: 'cordova',
database: 'test',
location: 'default',
logging: ['error', 'query', 'schema'],
synchronize: true,
entities: [
Author,
Category,
Post
]
});
} else {
// Running app in browser
await createConnection({
type: 'sqljs',
autoSave: true,
location: 'browser',
logging: ['error', 'query', 'schema'],
synchronize: true,
entities: [
Author,
Category,
Post
]
});
}

this.rootPage = HomePage;
});
Expand Down

0 comments on commit 7b17a13

Please sign in to comment.