Skip to content

Commit 819104a

Browse files
committed
removed database provider to follow typeorm code style
1 parent 58264e4 commit 819104a

4 files changed

Lines changed: 27 additions & 48 deletions

File tree

config.xml

Lines changed: 7 additions & 7 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-
<plugin name="ionic-plugin-keyboard" spec="~2.2.1" />
85-
<plugin name="cordova-plugin-whitelist" spec="1.3.1" />
86-
<plugin name="cordova-plugin-statusbar" spec="2.2.2" />
87-
<plugin name="cordova-plugin-device" spec="1.1.4" />
88-
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1" />
84+
<engine name="android" spec="^6.2.3" />
85+
<engine name="ios" spec="^4.4.0" />
86+
<plugin name="cordova-plugin-device" spec="^1.1.4" />
87+
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
88+
<plugin name="cordova-plugin-statusbar" spec="^2.2.2" />
89+
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
8990
<plugin name="cordova-sqlite-storage" spec="^2.0.4" />
90-
<engine name="ios" spec="~4.4.0" />
91-
<engine name="android" spec="~6.2.3" />
91+
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
9292
</widget>

src/app/app.module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { StatusBar } from '@ionic-native/status-bar';
66

77
import { MyApp } from './app.component';
88
import { HomePage } from '../pages/home/home';
9-
import { DatabaseProvider } from '../providers/database';
109

1110
@NgModule({
1211
declarations: [
@@ -25,8 +24,7 @@ import { DatabaseProvider } from '../providers/database';
2524
providers: [
2625
StatusBar,
2726
SplashScreen,
28-
{provide: ErrorHandler, useClass: IonicErrorHandler},
29-
DatabaseProvider
27+
{provide: ErrorHandler, useClass: IonicErrorHandler}
3028
]
3129
})
3230
export class AppModule {}

src/pages/home/home.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component } from '@angular/core';
22
import { Platform, NavController } from 'ionic-angular';
3-
4-
import { DatabaseProvider } from '../../providers/database';
3+
import { createConnection, getRepository } from 'typeorm';
54

65
import { Author } from '../../entities/author';
76
import { Category } from '../../entities/category';
@@ -15,14 +14,30 @@ export class HomePage {
1514
private savedPost: boolean = false;
1615
private loadedPost: Post = null;
1716

18-
constructor(public navCtrl: NavController, private platform: Platform, private database: DatabaseProvider) { }
17+
constructor(public navCtrl: NavController, private platform: Platform) { }
1918

2019
ionViewDidLoad() {
2120
this.runDemo();
2221
}
2322

23+
async connect() {
24+
await createConnection({
25+
type: 'cordova',
26+
database: 'test',
27+
location: 'default',
28+
logging: ['error', 'query', 'schema'],
29+
synchronize: true,
30+
entities: [
31+
Author,
32+
Category,
33+
Post
34+
]
35+
});
36+
}
37+
2438
async runDemo() {
2539
await this.platform.ready();
40+
await this.connect();
2641
const category1 = new Category();
2742
category1.name = "TypeScript";
2843

@@ -38,8 +53,7 @@ export class HomePage {
3853
post.categories = [category1, category2];
3954
post.author = author;
4055

41-
const connection = await this.database.getConnection();
42-
const postRepository = connection.getRepository(Post);
56+
const postRepository = getRepository(Post);
4357
await postRepository.save(post);
4458

4559
console.log("Post has been saved");

src/providers/database.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)