Skip to content

Commit c336277

Browse files
committed
merge
2 parents 3cd9de2 + 04a067c commit c336277

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/fernandocode/ionic-database-builder/issues)
33

44
# ionic-database-builder
5-
Extended library from [database-builder](https://github.com/fernandocode/database-builder) to assist in creating and maintaining SQL commands. Allowing integrate execute commands with [SQLite ('@ionic-native/sqlite')](https://ionicframework.com/docs/native/sqlite/), [Web Sql](https://www.w3.org/TR/webdatabase/), etc. Through the interface injection 'DatabaseCreatorContract' returning an implementation of 'DatabaseObject'.
5+
Ionic module for [database-builder](https://github.com/fernandocode/database-builder) library. Allowing integrate execute commands with [SQLite ('@ionic-native/sqlite')](https://ionicframework.com/docs/native/sqlite/), [Web Sql](https://www.w3.org/TR/webdatabase/), etc. Through the interface injection 'DatabaseCreatorContract' returning an implementation of 'DatabaseObject'.
66

77
# Getting Started
88

@@ -65,6 +65,10 @@ import { DatabaseHelper } from 'database-builder';
6565
// Declare the implementation of 'DatabaseCreatorContract' that you want to use, you can include a proxy, use libraries with different signatures, or create mocks for tests, etc.
6666
useClass: SQLite
6767
},
68+
{
69+
// Enable log SQL execute
70+
useValue: false
71+
},
6872
// implementation of "DatabaseMigrationContract" to estrategy migration upgrade versions database
6973
DatabaseMigrationService
7074
),
@@ -141,6 +145,10 @@ import { DatabaseModule } from 'ionic-database-builder';
141145
// Declare the implementation of 'DatabaseCreatorContract' that you want to use, you can include a proxy, use libraries with different signatures, or create mocks for tests, etc.
142146
useClass: SQLite
143147
},
148+
{
149+
// Enable log SQL execute
150+
useValue: false
151+
},
144152
// implementation of "DatabaseMigrationContract" to estrategy migration upgrade versions database
145153
DatabaseMigrationService
146154
),

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ionic-database-builder",
3-
"version": "0.2.0-ionic.4-beta.2",
3+
"version": "0.2.0-ionic4-beta.3",
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
"main": "index.js",
66
"scripts": {
@@ -11,7 +11,8 @@
1111
"lint": "ng lint",
1212
"e2e": "ng e2e",
1313
"packagr": "ng-packagr -p ng-package.json",
14-
"publish-npm": "npm run packagr && npm publish dist"
14+
"publish-npm": "npm run packagr && npm publish dist",
15+
"publish-npm-beta": "npm run packagr && npm publish dist --tag ionic4-beta"
1516
},
1617
"repository": {
1718
"type": "git",

src/test/mapper.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ describe('Mapper', () => {
106106
const database: Database = TestBed.get(Database);
107107
database.crud().then(crud => {
108108
const result = crud.insert(Cliente, clienteToSave).compile();
109-
expect(result.params.toString()).toEqual([
109+
expect(result[0].params.toString()).toEqual([
110110
clienteToSave.codeImport, clienteToSave.razaoSocial, clienteToSave.apelido,
111111
clienteToSave.desativo, clienteToSave.cidade.codeImport, clienteToSave.classificacao.codeImport
112112
].toString());
113-
expect(result.query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)');
113+
expect(result[0].query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)');
114114
});
115115
}));
116116

@@ -122,11 +122,11 @@ describe('Mapper', () => {
122122
database.beginTransaction().then(crud => {
123123
try {
124124
const result = crud.insert(Cliente, clienteToSave).compile();
125-
expect(result.params.toString()).toEqual([
125+
expect(result[0].params.toString()).toEqual([
126126
clienteToSave.codeImport, clienteToSave.razaoSocial, clienteToSave.apelido,
127127
clienteToSave.desativo, clienteToSave.cidade.codeImport, clienteToSave.classificacao.codeImport
128128
].toString());
129-
expect(result.query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)');
129+
expect(result[0].query).toEqual('INSERT INTO Cliente (codeImport, razaoSocial, apelido, desativo, cidade_codeImport, classificacao_codeImport) VALUES (?, ?, ?, ?, ?, ?)');
130130
database.commitTransaction().then(x => {
131131
expect(x).toEqual(true);
132132
}).catch(rollback);

src/utils/buildable-database-manager.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,27 @@ export abstract class BuildableDatabaseManager extends DatabaseManager {
9494
return new Promise((resolve, reject) => {
9595
this.databaseInstance().then(database => {
9696
const executable = new ExecutableBuilder(this.enableLog);
97-
executable.execute({
97+
executable.execute([{
9898
query: sql,
9999
params: params
100-
} as QueryCompiled, database)
101-
.then((cursor: DatabaseResult) => {
102-
resolve(cursor);
100+
} as QueryCompiled], database)
101+
.then((cursor: DatabaseResult[]) => {
102+
resolve(cursor[0]);
103103
});
104104
})
105-
.catch(reject);
105+
.catch(reject);
106106
});
107107
}
108108

109109
public query<T>(typeT: new () => T, alias: string = void 0): Promise<Query<T>> {
110110
return new Promise((resolve, reject) => {
111111
this.databaseInstance()
112112
.then(database => {
113-
resolve(new Query(typeT, alias, this._mapper.get(typeT), database, this.enableLog));
113+
const that = this;
114+
resolve(new Query(typeT, alias,
115+
(tKey: (new () => any) | string) => {
116+
return that._mapper.get(tKey);
117+
}, this._mapper.get(typeT).mapperTable, database, this.enableLog));
114118
}, reject)
115119
.catch(reject);
116120
});

0 commit comments

Comments
 (0)