Skip to content

Commit c08efc6

Browse files
author
fernandocode
committed
Merge branch 'managed-transaction'
2 parents a6b8a4a + 1eb9486 commit c08efc6

19 files changed

+881
-240
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ npm-debug.log
4040
yarn-error.log
4141
testem.log
4242
/typings
43+
debug.log
4344

4445
# System Files
4546
.DS_Store

package-lock.json

Lines changed: 385 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"@angular/platform-browser-dynamic": "~7.2.0",
2424
"@angular/router": "~7.2.0",
2525
"core-js": "^2.5.4",
26-
"database-builder": "^0.5.0-alpha.3",
26+
"database-builder": "^0.5.0-alpha.15",
2727
"moment": "^2.22.0",
28-
"rxjs": "6.4.0",
29-
"tslib": "^1.9.0",
28+
"rxjs": "^6.5.3",
29+
"tslib": "^1.10.0",
3030
"zone.js": "~0.8.26"
3131
},
3232
"devDependencies": {
@@ -35,9 +35,9 @@
3535
"@angular/cli": "~7.3.5",
3636
"@angular/compiler-cli": "~7.2.0",
3737
"@angular/language-service": "~7.2.0",
38-
"@types/node": "~8.9.4",
3938
"@types/jasmine": "~2.8.8",
4039
"@types/jasminewd2": "~2.0.3",
40+
"@types/node": "~8.9.4",
4141
"codelyzer": "~4.5.0",
4242
"jasmine-core": "~2.99.1",
4343
"jasmine-spec-reporter": "~4.2.1",
@@ -50,7 +50,6 @@
5050
"protractor": "~5.4.0",
5151
"ts-node": "~7.0.0",
5252
"tsickle": ">=0.34.0",
53-
"tslib": "^1.9.0",
5453
"tslint": "~5.11.0",
5554
"typescript": "~3.2.2"
5655
}

projects/ionic-database-builder/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ionic-database-builder",
3-
"version": "0.3.6",
3+
"version": "0.4.0-alpha.2",
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",
@@ -36,6 +36,6 @@
3636
"peerDependencies": {
3737
"@angular/common": "^7.2.0",
3838
"@angular/core": "^7.2.0",
39-
"database-builder": "^0.3.10"
39+
"database-builder": "^0.5.0-alpha.15"
4040
}
4141
}

projects/ionic-database-builder/src/lib/services/database-migration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class DatabaseMigration extends DatabaseMigrationBase implements Database
3232
const mappers = this._settings.mapper(this._injector);
3333

3434
// remove dados offline da versão anterior, pois o formato dos dados foi alterado de uma versão para a outra
35-
const ddl = new Ddl(database, mappers, true);
35+
const ddl = new Ddl({ database, getMapper: mappers, enableLog: true });
3636
mappers.forEachMapper((value, key) => {
3737
if (!value.readOnly) {
3838
observablesWait.push(ddl.drop(value.newable).execute());
Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,9 @@
11
import { Injectable } from '@angular/core';
22
import { WebSqlDatabaseAdapter } from 'database-builder';
33

4-
// /**
5-
// * @deprecated use WebSqlDatabaseService
6-
// */
7-
// @Injectable()
8-
// export class DatabaseBrowserService extends WebSqlDatabaseAdapter {
9-
// constructor() {
10-
// super((window as any));
11-
// }
12-
// }
13-
144
@Injectable()
155
export class WebSqlDatabaseService extends WebSqlDatabaseAdapter {
166
constructor() {
177
super((window as any));
188
}
199
}
20-
21-
// export class DatabaseBrowserService implements DatabaseCreatorContract {
22-
23-
// create(config: DatabaseConfig): Promise<DatabaseObject> {
24-
// console.warn("Use WebSQL only for testing, some browsers no longer support WebSQL! \\o/");
25-
// return new Promise<DatabaseObject>((resolve, reject) => {
26-
// // o método OpenDatabase precisa de 4 parametros; o nome do banco de dados, a versão, a descrição e o tamanho estimado (em bytes)
27-
// const db = (window as any).openDatabase(config.name, "1.0", config.name, 200000);
28-
29-
// // de qualquer forma, sempre teste que o objeto foi instanciado direito antes de usá-lo
30-
// if (!db) {
31-
// reject("Não foi possivel iniciar o banco de dados no Browser!");
32-
// }
33-
// resolve(<DatabaseObject>{
34-
// executeSql: (statement: string, params: any): Promise<DatabaseResult> => {
35-
// return new Promise<DatabaseResult>((resolve, reject) => {
36-
// if (
37-
// statement.toUpperCase().indexOf("TRANSACTION") > -1
38-
// ||
39-
// statement.toUpperCase().indexOf("COMMIT") > -1
40-
// ) {
41-
// console.warn(`command sql ignored: '${statement}'`);
42-
// resolve({} as DatabaseResult);
43-
// return;
44-
// }
45-
// db.transaction((transaction: any) => {
46-
// transaction.executeSql(statement, Array.isArray(params) ? params : [],
47-
// (s: any, r: any) => resolve(r),
48-
// (e: any, err: any) => {
49-
// reject(err)
50-
// });
51-
// });
52-
// });
53-
// },
54-
// transaction:
55-
// (fn: (transaction: DatabaseBaseTransaction) => void): Promise<any> => {
56-
// return db.transaction((transiction: any) => {
57-
// fn({
58-
// executeSql: (sql: string, values: any): Promise<DatabaseResult> => {
59-
// return new Promise<DatabaseResult>((resolve, reject) => {
60-
// transiction.executeSql(sql, Array.isArray(values) ? values : [],
61-
// (s: any, r: any) => {
62-
// resolve(r)
63-
// },
64-
// (e: any, err: any) => {
65-
// reject(err)
66-
// });
67-
// });
68-
// }
69-
// });
70-
// });
71-
// }
72-
// });
73-
// });
74-
// }
75-
// }

projects/ionic-database-builder/src/lib/utils/buildable-database-manager.ts

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DatabaseBaseTransaction, DatabaseResult } from 'database-builder';
1+
import { DatabaseBaseTransaction, DatabaseResult, DatabaseBuilderError } from 'database-builder';
22
import { DatabaseManager } from './database-manager';
33
import { Crud, DatabaseObject, Ddl, ExecutableBuilder, GetMapper, Query, QueryCompiled } from 'database-builder';
44
import { DatabaseFactoryContract } from './database-factory-contract';
@@ -30,6 +30,18 @@ export abstract class BuildableDatabaseManager extends DatabaseManager {
3030
return database;
3131
}
3232

33+
public managedTransaction(): Observable<ManagedTransaction> {
34+
return from(this.databaseInstance()).pipe(mergeMap(database => {
35+
if (!database.managedTransaction) {
36+
throw new DatabaseBuilderError('Managed Transaction not supported in current middleware!');
37+
}
38+
return of(database.managedTransaction());
39+
}));
40+
}
41+
42+
/**
43+
* @deprecated Use managedTransaction()
44+
*/
3345
public newTransaction(successTransaction: () => void): Observable<DatabaseBaseTransaction> {
3446
return new Observable((observer: Observer<DatabaseBaseTransaction>) => {
3547
this.databaseInstance()
@@ -53,29 +65,14 @@ export abstract class BuildableDatabaseManager extends DatabaseManager {
5365
});
5466
}
5567

56-
public managedTransaction(): Observable<ManagedTransaction> {
57-
return from(this.databaseInstance()).pipe(mergeMap(database => of(database.managedTransaction())));
58-
// return new Observable<ManagedTransaction>((observer) => {
59-
// const database = await this.databaseInstance();
60-
// // this.newTransaction(successTransaction)
61-
// // .subscribe((transaction) => {
62-
// // observer.next(new Crud(transaction, this._mapper, this.enableLog));
63-
// // observer.complete();
64-
// // }, error => {
65-
// // observer.error(error);
66-
// // observer.complete();
67-
// // });
68-
// });
69-
}
70-
7168
/**
7269
* @deprecated Use managedTransaction()
7370
*/
7471
public transaction(successTransaction: () => void): Observable<Crud> {
7572
return new Observable((observer: Observer<Crud>) => {
7673
this.newTransaction(successTransaction)
7774
.subscribe((transaction) => {
78-
observer.next(new Crud(transaction, this._mapper, this.enableLog));
75+
observer.next(new Crud({ database: transaction, getMapper: this._mapper, enableLog: this.enableLog }));
7976
observer.complete();
8077
}, error => {
8178
observer.error(error);
@@ -142,35 +139,13 @@ export abstract class BuildableDatabaseManager extends DatabaseManager {
142139
return new Observable((observer: Observer<Crud>) => {
143140
this.databaseInstance()
144141
.then(database => {
145-
observer.next(new Crud(database, this._mapper, this.enableLog));
142+
observer.next(new Crud({ database, getMapper: this._mapper, enableLog: this.enableLog }));
146143
observer.complete();
147144
})
148145
.catch(error => { observer.error(error); observer.complete(); });
149146
});
150147
}
151148

152-
// public batch(compiled: QueryCompiled[]): Observable<DatabaseResult[]> {
153-
// return new Observable((observer: Observer<DatabaseResult[]>) => {
154-
// this.databaseInstance()
155-
// .then(database => {
156-
// const executable = new ExecutableBuilder(this.enableLog);
157-
// console.log('batch ::: ', database);
158-
// executable.executeBatch(compiled, database)
159-
// .subscribe((cursor: DatabaseResult[]) => {
160-
// observer.next(cursor);
161-
// observer.complete();
162-
// }, err => {
163-
// observer.error(err);
164-
// observer.complete();
165-
// });
166-
// })
167-
// .catch(err => {
168-
// observer.error(err);
169-
// observer.complete();
170-
// });
171-
// });
172-
// }
173-
174149
public sql(sql: string, params: any[] = []): Observable<DatabaseResult> {
175150
return new Observable((observer: Observer<DatabaseResult>) => {
176151
this.databaseInstance()
@@ -200,10 +175,15 @@ export abstract class BuildableDatabaseManager extends DatabaseManager {
200175
this.databaseInstance()
201176
.then(database => {
202177
const that = this;
203-
observer.next(new Query(typeT, alias,
204-
(tKey: (new () => any) | string) => {
178+
observer.next(new Query(typeT, {
179+
alias,
180+
getMapper: (tKey: (new () => any) | string) => {
205181
return that._mapper.get(tKey);
206-
}, this._mapper.get(typeT).mapperTable, database, this.enableLog));
182+
},
183+
mapperTable: this._mapper.get(typeT).mapperTable,
184+
database,
185+
enableLog: this.enableLog
186+
}));
207187
observer.complete();
208188
})
209189
.catch(error => {
@@ -217,7 +197,7 @@ export abstract class BuildableDatabaseManager extends DatabaseManager {
217197
return new Observable((observer: Observer<Ddl>) => {
218198
this.databaseInstance()
219199
.then(database => {
220-
observer.next(new Ddl(database, this._mapper, this.enableLog));
200+
observer.next(new Ddl({ database, getMapper: this._mapper, enableLog: this.enableLog }));
221201
observer.complete();
222202
})
223203
.catch(error => {

projects/ionic-database-builder/src/lib/utils/database-migration-base.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import * as momentNs from 'moment';
32
const moment = momentNs;
43
import { DatabaseObject } from 'database-builder';

src/app/cidade.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Cidade', () => {
4545

4646
const cidade: Cidade = new Cidade();
4747
cidade.nome = 'Cidade Test';
48-
const insertResult = await crud.insert(Cidade, cidade).execute().toPromise();
48+
const insertResult = await crud.insert(Cidade, { modelToSave: cidade }).execute().toPromise();
4949
expect(insertResult[0].insertId).toBeGreaterThan(0);
5050
expect(insertResult[0].rowsAffected).toEqual(1);
5151
});
@@ -59,12 +59,12 @@ describe('Cidade', () => {
5959

6060
const cidade: Cidade = new Cidade();
6161
cidade.nome = 'Cidade Test';
62-
const insertResult = await crud.insert(Cidade, cidade).execute().toPromise();
62+
const insertResult = await crud.insert(Cidade, { modelToSave: cidade }).execute().toPromise();
6363
expect(insertResult[0].insertId).toBeGreaterThan(0);
6464
expect(insertResult[0].rowsAffected).toEqual(1);
6565

6666
cidade.nome = 'Nova Cidade';
67-
const updateResult = await crud.update(Cidade, cidade)
67+
const updateResult = await crud.update(Cidade, { modelToSave: cidade })
6868
.where(where => where.equal(x => x.codeImport, cidade.codeImport))
6969
.execute().toPromise();
7070
expect(updateResult[0].rowsAffected).toEqual(1);
@@ -79,13 +79,13 @@ describe('Cidade', () => {
7979

8080
const cidade: Cidade = new Cidade();
8181
cidade.nome = 'Cidade Test';
82-
const result = await crud.insert(Cidade, cidade).execute().toPromise();
82+
const result = await crud.insert(Cidade, { modelToSave: cidade }).execute().toPromise();
8383
expect(result[0].insertId).toBeGreaterThan(0);
8484
expect(result[0].rowsAffected).toEqual(1);
8585

8686
cidade.nome = 'Nova Cidade';
8787
cidade.uf = void 0;
88-
const updateResult = await crud.update(Cidade, cidade)
88+
const updateResult = await crud.update(Cidade, { modelToSave: cidade })
8989
.where(where => where.equal(x => x.codeImport, cidade.codeImport))
9090
.execute().toPromise();
9191
expect(updateResult[0].rowsAffected).toEqual(1);

src/app/database/data-to-test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { GuidClazz } from './models/guid-clazz';
2+
3+
export const guidClazz = {
4+
description: 'Condicao Pagamento 25'
5+
} as GuidClazz;

0 commit comments

Comments
 (0)