Skip to content

Commit 7b17a13

Browse files
committed
added conditional db connection for device and browser
1 parent 755d118 commit 7b17a13

3 files changed

Lines changed: 96 additions & 77 deletions

File tree

config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@
8181
<splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
8282
<icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
8383
</platform>
84-
<engine name="android" spec="^6.3.0" />
84+
<engine name="android" spec="^6.4.0" />
8585
<engine name="ios" spec="^4.5.0" />
86-
<plugin name="cordova-plugin-device" spec="^1.1.4" />
8786
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
8887
<plugin name="cordova-plugin-statusbar" spec="^2.2.2" />
8988
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
9089
<plugin name="cordova-sqlite-storage" spec="^2.0.4" />
9190
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
91+
<plugin name="cordova-plugin-device" spec="^1.1.7" />
9292
</widget>

package.json

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
11
{
2-
"name": "ionic-example",
3-
"version": "1.0.0",
4-
"author": "Daniel Lang",
5-
"scripts": {
6-
"clean": "ionic-app-scripts clean",
7-
"build": "ionic-app-scripts build",
8-
"lint": "ionic-app-scripts lint",
9-
"ionic:build": "ionic-app-scripts build",
10-
"ionic:serve": "ionic-app-scripts serve"
11-
},
12-
"config": {
13-
"ionic_webpack": "./config/webpack.config.js"
14-
},
15-
"dependencies": {
16-
"@angular/common": "4.4.3",
17-
"@angular/compiler": "4.4.3",
18-
"@angular/compiler-cli": "4.4.3",
19-
"@angular/core": "4.4.3",
20-
"@angular/forms": "4.4.3",
21-
"@angular/http": "4.4.3",
22-
"@angular/platform-browser": "4.4.3",
23-
"@angular/platform-browser-dynamic": "4.4.3",
24-
"@ionic-native/core": "4.3.0",
25-
"@ionic-native/splash-screen": "4.3.0",
26-
"@ionic-native/status-bar": "4.3.0",
27-
"@ionic/storage": "2.0.1",
28-
"cordova-android": "^6.3.0",
29-
"cordova-ios": "^4.5.0",
30-
"cordova-plugin-device": "^1.1.4",
31-
"cordova-plugin-splashscreen": "^4.0.3",
32-
"cordova-plugin-statusbar": "^2.2.2",
33-
"cordova-plugin-whitelist": "^1.3.1",
34-
"cordova-sqlite-storage": "^2.0.4",
35-
"ionic-angular": "3.7.0",
36-
"ionic-plugin-keyboard": "^2.2.1",
37-
"ionicons": "3.0.0",
38-
"rxjs": "5.4.3",
39-
"sw-toolbox": "3.6.0",
40-
"typeorm": "0.1.6",
41-
"zone.js": "0.8.17"
42-
},
43-
"devDependencies": {
44-
"@ionic/app-scripts": "^3.0.0",
45-
"@types/node": "^8.0.31",
46-
"sql.js": "^0.5.0",
47-
"typescript": "2.3.4"
48-
},
49-
"description": "An Ionic project",
50-
"cordova": {
51-
"plugins": {
52-
"cordova-plugin-device": {},
53-
"cordova-plugin-splashscreen": {},
54-
"cordova-plugin-statusbar": {},
55-
"cordova-plugin-whitelist": {},
56-
"ionic-plugin-keyboard": {},
57-
"cordova-sqlite-storage": {}
2+
"name": "ionic-example",
3+
"version": "1.0.0",
4+
"author": "Daniel Lang",
5+
"scripts": {
6+
"clean": "ionic-app-scripts clean",
7+
"build": "ionic-app-scripts build",
8+
"lint": "ionic-app-scripts lint",
9+
"ionic:build": "ionic-app-scripts build",
10+
"ionic:serve": "ionic-app-scripts serve"
5811
},
59-
"platforms": [
60-
"android",
61-
"ios"
62-
]
63-
}
64-
}
12+
"config": {
13+
"ionic_webpack": "./config/webpack.config.js"
14+
},
15+
"dependencies": {
16+
"@angular/common": "4.4.3",
17+
"@angular/compiler": "4.4.3",
18+
"@angular/compiler-cli": "4.4.3",
19+
"@angular/core": "4.4.3",
20+
"@angular/forms": "4.4.3",
21+
"@angular/http": "4.4.3",
22+
"@angular/platform-browser": "4.4.3",
23+
"@angular/platform-browser-dynamic": "4.4.3",
24+
"@ionic-native/core": "4.3.0",
25+
"@ionic-native/splash-screen": "4.3.0",
26+
"@ionic-native/status-bar": "4.3.0",
27+
"@ionic/storage": "2.0.1",
28+
"cordova-android": "^6.4.0",
29+
"cordova-ios": "^4.5.0",
30+
"cordova-plugin-device": "^1.1.7",
31+
"cordova-plugin-splashscreen": "^4.0.3",
32+
"cordova-plugin-statusbar": "^2.2.2",
33+
"cordova-plugin-whitelist": "^1.3.1",
34+
"cordova-sqlite-storage": "^2.0.4",
35+
"ionic-angular": "3.7.0",
36+
"ionic-plugin-keyboard": "^2.2.1",
37+
"ionicons": "3.0.0",
38+
"rxjs": "5.4.3",
39+
"sw-toolbox": "3.6.0",
40+
"typeorm": "0.1.6",
41+
"zone.js": "0.8.17"
42+
},
43+
"devDependencies": {
44+
"@ionic/app-scripts": "^3.0.0",
45+
"@types/node": "^8.0.31",
46+
"sql.js": "^0.5.0",
47+
"typescript": "2.3.4"
48+
},
49+
"description": "An Ionic project",
50+
"cordova": {
51+
"plugins": {
52+
"cordova-plugin-device": {},
53+
"cordova-plugin-splashscreen": {},
54+
"cordova-plugin-statusbar": {},
55+
"cordova-plugin-whitelist": {},
56+
"ionic-plugin-keyboard": {},
57+
"cordova-sqlite-storage": {}
58+
},
59+
"platforms": [
60+
"android",
61+
"ios"
62+
]
63+
}
64+
}

src/app/app.component.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Post } from '../entities/post';
1414
templateUrl: 'app.html'
1515
})
1616
export class MyApp {
17-
rootPage:any;
17+
rootPage: any;
1818

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

26-
await createConnection({
27-
type: 'cordova',
28-
database: 'test',
29-
location: 'default',
30-
logging: ['error', 'query', 'schema'],
31-
synchronize: true,
32-
entities: [
33-
Author,
34-
Category,
35-
Post
36-
]
37-
});
26+
// Depending on the machine the app is running on, configure
27+
// different database connections
28+
if(platform.is('cordova')) {
29+
// Running on device or emulator
30+
await createConnection({
31+
type: 'cordova',
32+
database: 'test',
33+
location: 'default',
34+
logging: ['error', 'query', 'schema'],
35+
synchronize: true,
36+
entities: [
37+
Author,
38+
Category,
39+
Post
40+
]
41+
});
42+
} else {
43+
// Running app in browser
44+
await createConnection({
45+
type: 'sqljs',
46+
autoSave: true,
47+
location: 'browser',
48+
logging: ['error', 'query', 'schema'],
49+
synchronize: true,
50+
entities: [
51+
Author,
52+
Category,
53+
Post
54+
]
55+
});
56+
}
3857

3958
this.rootPage = HomePage;
4059
});

0 commit comments

Comments
 (0)