Skip to content

Commit

Permalink
removed database provider to follow typeorm code style
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lang committed Nov 13, 2017
1 parent 58264e4 commit 819104a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 48 deletions.
14 changes: 7 additions & 7 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>
<plugin name="ionic-plugin-keyboard" spec="~2.2.1" />
<plugin name="cordova-plugin-whitelist" spec="1.3.1" />
<plugin name="cordova-plugin-statusbar" spec="2.2.2" />
<plugin name="cordova-plugin-device" spec="1.1.4" />
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1" />
<engine name="android" spec="^6.2.3" />
<engine name="ios" spec="^4.4.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" />
<engine name="ios" spec="~4.4.0" />
<engine name="android" spec="~6.2.3" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
</widget>
4 changes: 1 addition & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { DatabaseProvider } from '../providers/database';

@NgModule({
declarations: [
Expand All @@ -25,8 +24,7 @@ import { DatabaseProvider } from '../providers/database';
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
DatabaseProvider
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
24 changes: 19 additions & 5 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { Platform, NavController } from 'ionic-angular';

import { DatabaseProvider } from '../../providers/database';
import { createConnection, getRepository } from 'typeorm';

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

constructor(public navCtrl: NavController, private platform: Platform, private database: DatabaseProvider) { }
constructor(public navCtrl: NavController, private platform: Platform) { }

ionViewDidLoad() {
this.runDemo();
}

async connect() {
await createConnection({
type: 'cordova',
database: 'test',
location: 'default',
logging: ['error', 'query', 'schema'],
synchronize: true,
entities: [
Author,
Category,
Post
]
});
}

async runDemo() {
await this.platform.ready();
await this.connect();
const category1 = new Category();
category1.name = "TypeScript";

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

const connection = await this.database.getConnection();
const postRepository = connection.getRepository(Post);
const postRepository = getRepository(Post);
await postRepository.save(post);

console.log("Post has been saved");
Expand Down
33 changes: 0 additions & 33 deletions src/providers/database.ts

This file was deleted.

0 comments on commit 819104a

Please sign in to comment.