Skip to content

Commit e2fdc05

Browse files
author
fernandocode
committed
v.0.3.5
1 parent 5b0bd14 commit e2fdc05

File tree

6 files changed

+129
-7
lines changed

6 files changed

+129
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"start": "ng serve --aot",
77
"build": "ng build ionic-database-builder --prod",
88
"postbuild": "node scripts/copy-artifacts.js",
9-
"test": "ng test",
9+
"test": "ng test --prod",
1010
"lint": "ng lint",
1111
"e2e": "ng e2e",
1212
"publish": "npm run build && npm publish dist/ionic-database-builder"

projects/ionic-database-builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ionic-database-builder",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"description": "Extended library from database-builder to assist in creating and maintaining SQL commands. Allowing integrate execute commands with SQLite ('@ionic-native/sqlite'), Web Sql, etc. Through the interface injection 'DatabaseCreatorContract' returning an implementation of 'DatabaseObject'.",
55
"repository": {
66
"type": "git",

projects/ionic-database-builder/src/lib/ionic-database-builder.module.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { DatabaseHelperService } from './services/database-helper.service';
1111
import { DatabaseFactoryDefault } from './defaults/database-factory-default';
1212
import { DatabaseFactoryContract } from './utils/database-factory-contract';
1313
import { PlatformLoad } from './utils/platform-load';
14+
import { PlatformLoadDefault } from './utils/platform-load-default';
1415

1516
@NgModule({
1617
providers: [
@@ -20,6 +21,10 @@ import { PlatformLoad } from './utils/platform-load';
2021
{
2122
provide: DatabaseFactoryContract,
2223
useClass: DatabaseFactoryDefault
24+
},
25+
{
26+
provide: PLATFORM_LOAD,
27+
useClass: PlatformLoadDefault
2328
}
2429
]
2530
})
@@ -35,14 +40,14 @@ export class IonicDatabaseBuilderModule {
3540
public static forSimple(
3641
isEnableLogProvider: boolean = false,
3742
isAvailableProvider: boolean = true,
38-
platformLoad: PlatformLoad = { ready: () => Promise.resolve() },
43+
platformLoad: Type<PlatformLoad> = PlatformLoadDefault
3944
): ModuleWithProviders {
4045
return {
4146
ngModule: IonicDatabaseBuilderModule,
4247
providers: [
4348
{ provide: IS_ENABLE_LOG, useValue: isEnableLogProvider },
4449
{ provide: IS_AVAILABLE_DATABASE, useValue: isAvailableProvider },
45-
{ provide: PLATFORM_LOAD, useValue: platformLoad },
50+
{ provide: PLATFORM_LOAD, useClass: platformLoad },
4651
]
4752
};
4853
}
@@ -51,7 +56,7 @@ export class IonicDatabaseBuilderModule {
5156
settingsProvider: Type<DatabaseSettingsFactoryContract>,
5257
databaseCreatorProvider: Type<DatabaseCreatorContract>,
5358
databaseMigrationContract: Type<DatabaseMigrationContract>,
54-
platformLoad: PlatformLoad = { ready: () => Promise.resolve() },
59+
platformLoad: Type<PlatformLoad> = PlatformLoadDefault,
5560
isEnableLogProvider: boolean = false,
5661
isAvailableProvider: boolean = true,
5762
): ModuleWithProviders {
@@ -62,7 +67,7 @@ export class IonicDatabaseBuilderModule {
6267
{ provide: DATABASE_CREATOR, useClass: databaseCreatorProvider },
6368
{ provide: DATABASE_MIGRATION, useClass: databaseMigrationContract },
6469
{ provide: IS_ENABLE_LOG, useValue: isEnableLogProvider },
65-
{ provide: PLATFORM_LOAD, useValue: platformLoad },
70+
{ provide: PLATFORM_LOAD, useClass: platformLoad },
6671
{ provide: IS_AVAILABLE_DATABASE, useValue: isAvailableProvider },
6772
]
6873
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { PlatformLoad } from './platform-load';
2+
3+
export class PlatformLoadDefault extends PlatformLoad {
4+
public ready(): Promise<void> {
5+
return Promise.resolve();
6+
}
7+
}

src/app/batch.spec.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// import { Cidade } from './database/models/cidade';
2+
// import { TestBed, async } from '@angular/core/testing';
3+
// import { AppComponent } from './app.component';
4+
// import { DatabaseSettingsFactory } from './database/factory/database-settings-factory';
5+
// import { DatabaseMigrationService } from './database/provider/database-migration-service';
6+
// import { TableMapper } from './database/mapper/table-mapper';
7+
// import { Uf } from './database/models/uf';
8+
// import { Regiao } from './database/models/regiao';
9+
// import { SubRegiao } from './database/models/sub-regiao';
10+
// import { Classificacao } from './database/models/classificacao';
11+
// import { Cliente } from './database/models/cliente';
12+
// import { IonicDatabaseBuilderModule, WebSqlDatabaseService, Database } from 'projects/ionic-database-builder/src/public_api';
13+
14+
// describe('Batch Test', () => {
15+
// beforeEach(async(() => {
16+
// TestBed.configureTestingModule({
17+
// declarations: [
18+
// AppComponent
19+
// ],
20+
// imports: [
21+
// IonicDatabaseBuilderModule.forRoot(
22+
// DatabaseSettingsFactory,
23+
// WebSqlDatabaseService,
24+
// DatabaseMigrationService,
25+
// { ready: () => Promise.resolve() },
26+
// false,
27+
// true,
28+
// )
29+
// ],
30+
// providers: [
31+
// TableMapper
32+
// ],
33+
// });
34+
// }));
35+
36+
// const clienteToSave = {
37+
// codeImport: 1,
38+
// razaoSocial: void 0,
39+
// apelido: 'Apelido',
40+
// cidade: {
41+
// codeImport: 2,
42+
// nome: 'Cidade',
43+
// uf: {
44+
// codeImport: 'SC',
45+
// nome: 'Santa Catarina'
46+
// } as Uf,
47+
// subRegiao: {
48+
// codeImport: 4,
49+
// nome: 'Sub Região',
50+
// regiao: {
51+
// codeImport: 5,
52+
// nome: 'Região'
53+
// } as Regiao
54+
// } as SubRegiao,
55+
// } as Cidade,
56+
// classificacao: {
57+
// codeImport: 3,
58+
// descricao: 'Top'
59+
// } as Classificacao,
60+
// desativo: false
61+
// } as Cliente;
62+
63+
// it('batch simple', async () => {
64+
// const database: Database = TestBed.get(Database);
65+
// const crud = await database.crud().toPromise();
66+
67+
// const clienteDelete = crud.delete(Cliente).compile();
68+
69+
// const insert = crud.insert(Cliente, clienteToSave);
70+
// const clienteInsert = insert.compile();
71+
// expect(clienteInsert[0].params.toString()).toEqual([
72+
// clienteToSave.codeImport, clienteToSave.razaoSocial, clienteToSave.apelido,
73+
// clienteToSave.desativo, clienteToSave.cidade.codeImport, clienteToSave.classificacao.codeImport
74+
// ].toString());
75+
// expect(clienteInsert[0].query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)');
76+
77+
// const r = await database.batch([clienteDelete[0], clienteInsert[0]]).toPromise();
78+
// console.log("result", r);
79+
80+
// // const insertResult = await insert.execute().toPromise();
81+
// // expect(insertResult[0].insertId).toBeGreaterThan(0);
82+
83+
// // const queryResultNull = await crud.query(Cliente)
84+
// // .where(where => where.isNull(x => x.razaoSocial))
85+
// // .toList().toPromise();
86+
87+
// // expect(queryResultNull.length).toEqual(1);
88+
// });
89+
90+
// // it('Test transaction mapper insert T', async () => {
91+
// // const database: Database = TestBed.get(Database);
92+
// // const rollback = () => {
93+
// // database.rollbackTransaction().toPromise().then().catch();
94+
// // };
95+
// // const crud = await database.beginTransaction().toPromise();
96+
// // try {
97+
// // const result = crud.insert(Cliente, clienteToSave).compile();
98+
// // expect(result[0].params.toString()).toEqual([
99+
// // clienteToSave.codeImport, clienteToSave.razaoSocial, clienteToSave.apelido,
100+
// // clienteToSave.desativo, clienteToSave.cidade.codeImport, clienteToSave.classificacao.codeImport
101+
// // ].toString());
102+
// // expect(result[0].query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)');
103+
// // const commitResult = await database.commitTransaction().toPromise();
104+
// // expect(commitResult).toEqual(true);
105+
// // } catch (e) {
106+
// // rollback();
107+
// // }
108+
// // });
109+
// });

src/app/simple.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Regiao } from './database/models/regiao';
1010
import { SubRegiao } from './database/models/sub-regiao';
1111
import { Classificacao } from './database/models/classificacao';
1212
import { Cliente } from './database/models/cliente';
13+
import { PlatformLoadDefault } from 'projects/ionic-database-builder/src/lib/utils/platform-load-default';
1314

1415
describe('Simple Test injector component', () => {
1516
beforeEach(async(() => {
@@ -22,7 +23,7 @@ describe('Simple Test injector component', () => {
2223
DatabaseSettingsFactory,
2324
WebSqlDatabaseService,
2425
DatabaseMigrationService,
25-
{ ready: () => Promise.resolve() },
26+
PlatformLoadDefault,
2627
false,
2728
true,
2829
)

0 commit comments

Comments
 (0)