Skip to content

Commit e35e1aa

Browse files
committed
v.0.0.1 published
1 parent f63e219 commit e35e1aa

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"url": "git+https://github.com/fernandocode/ionic-database-builder.git"
1212
},
1313
"keywords": [
14+
"ionic",
1415
"orm",
1516
"database",
1617
"builder",
@@ -26,8 +27,7 @@
2627
"ddl",
2728
"create-table",
2829
"drop-table",
29-
"alter-table",
30-
"ionic"
30+
"alter-table"
3131
],
3232
"author": "Fernando Leal",
3333
"license": "MIT",

src/database.module.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
1+
import { DATABASE_NAME, VERSION } from "./dependency-injection-definition";
12
import { Observable } from "rxjs";
2-
import { ModuleWithProviders, NgModule } from "@angular/core";
3+
import { ModuleWithProviders, NgModule, Provider } from "@angular/core";
34
import { DatabaseHelperService } from "./utils/database-helper-service";
5+
import { DatabaseMigrationContract } from "./providers/database-migration-contract";
6+
import { DatabaseMigration } from "./providers/database-migration";
7+
import { Database } from "./providers/database";
48

59
@NgModule({
610
declarations: [
7-
// declare all components that your module uses
8-
// MyComponent
911
],
1012
exports: [
11-
// export the component(s) that you want others to be able to use
12-
// MyComponent
13+
Database
14+
],
15+
providers: [
16+
DatabaseMigration,
17+
Database
1318
]
1419
})
1520
export class DatabaseModule {
1621
// https://stackblitz.com/edit/ionic-j3f3ym
17-
public static forRoot(): ModuleWithProviders {
22+
public static forRoot(
23+
version: number,
24+
databaseName: string,
25+
databaseMigrationContract?: new () => DatabaseMigrationContract
26+
): ModuleWithProviders {
27+
const providers: Provider[] = [
28+
DatabaseHelperService,
29+
DatabaseMigrationContract,
30+
{
31+
provide: VERSION,
32+
useValue: version
33+
},
34+
{
35+
provide: DATABASE_NAME,
36+
useValue: databaseName
37+
}
38+
];
39+
if (databaseMigrationContract) {
40+
providers.push({
41+
provide: DatabaseMigrationContract,
42+
useClass: databaseMigrationContract
43+
});
44+
}
1845
return {
1946
ngModule: DatabaseModule,
20-
providers: [DatabaseHelperService]
47+
providers: providers
2148
};
2249
}
2350
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import { Injectable } from "@angular/core";
12
import { Version } from "./../model/version-model";
23
import { Observable } from "rxjs/Observable";
34

4-
export interface DatabaseMigrationContract {
5+
@Injectable()
6+
export class DatabaseMigrationContract {
57

6-
to(version: Version): Array<Observable<any>>;
8+
public to(version: Version): Array<Observable<any>> {
9+
return [];
10+
}
711
}

src/providers/database.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DatabaseMigration } from "./database-migration";
12
import { DATABASE_NAME, VERSION } from "./../dependency-injection-definition";
23
import { Inject, Injectable } from "@angular/core";
34
import { SQLite, SQLiteObject } from "@ionic-native/sqlite";
@@ -12,17 +13,14 @@ export class Database extends BuildableDatabaseManager {
1213
@Inject(DATABASE_NAME) private _databaseName: string,
1314
platform: Platform,
1415
sqlite: SQLite,
15-
getMapper: GetMapper
16+
getMapper: GetMapper,
17+
private _databaseMigration: DatabaseMigration
1618
) {
1719
super(platform, sqlite, getMapper);
1820
}
1921

20-
// protected migrationVersion(database: SQLiteObject, version: number): Promise<boolean> {
21-
// return this._migrationDatabase.version(database, version);
22-
// }
23-
2422
protected migrationVersion(database: SQLiteObject, version: number): Promise<boolean> {
25-
throw new Error("Method not implemented.");
23+
return this._databaseMigration.version(database, version);
2624
}
2725

2826
protected databaseName(): string {

0 commit comments

Comments
 (0)