Skip to content

Commit a2ab7de

Browse files
committed
update readme
1 parent 7f0b7f2 commit a2ab7de

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

dist.tgz

-2.74 KB
Binary file not shown.

dist/README.md

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ionic-database-builder
2-
Extended library from database-builder to assist in creating and maintaining SQL commands with integrate execute commands in SQLite ('@ionic-native/sqlite').
2+
Extended library from [database-builder](https://github.com/fernandocode/database-builder) to assist in creating and maintaining SQL commands with integrate execute commands in SQLite ('@ionic-native/sqlite').
33

44
# Getting Started
55

@@ -52,7 +52,7 @@ export class AppModule { }
5252

5353
```
5454

55-
**DatabaseMigration**
55+
**`DatabaseMigration`**
5656

5757
```ts
5858
import { Observable } from 'rxjs/Observable';
@@ -112,7 +112,7 @@ export class AppModule { }
112112

113113
```
114114

115-
**DatabaseSettingsFactory**
115+
**`DatabaseSettingsFactory`**
116116

117117
```ts
118118
import { EnvironmentService } from './../providers/environment-service';
@@ -136,4 +136,84 @@ export class DatabaseSettingsFactory extends DatabaseSettingsFactoryContract {
136136
}
137137

138138
}
139-
```
139+
```
140+
141+
**`MappersTable`**
142+
143+
```ts
144+
import { MappersTableSimple, DatabaseHelperService } from "ionic-database-builder";
145+
import { Injectable } from "@angular/core";
146+
147+
@Injectable()
148+
export class MappersTable extends MappersTableSimple {
149+
150+
constructor(_databaseHelper: DatabaseHelperService) {
151+
super(
152+
_databaseHelper,
153+
{
154+
references: false,
155+
referencesId: true,
156+
referencesIdRecursive: false,
157+
referencesIdColumn: void 0
158+
}
159+
);
160+
161+
this.mapper(false, void 0, this._defaultSettings,
162+
// Type models for mapper
163+
TestClazz,
164+
TestClazzRef
165+
);
166+
167+
this.add(TestClazzAdvanced, false, void 0, {
168+
references: false,
169+
referencesId: false,
170+
referencesIdRecursive: false
171+
}, metadata => {
172+
metadata
173+
// add column reference1_id
174+
.mapper(x => x.reference1.id)
175+
// add column reference1_anything
176+
.mapper(x => x.reference1.anything);
177+
});
178+
}
179+
}
180+
```
181+
182+
### Step 3: Use `Database` in Components
183+
184+
`DatabaseModule` provides the injection of `Database` in its components and services, as can be seen in the following example:
185+
186+
**`MyApp`**
187+
188+
```ts
189+
import { Database } from 'ionic-database-builder';
190+
import { Component } from '@angular/core';
191+
192+
@Component({
193+
templateUrl: 'app.html'
194+
})
195+
export class MyApp {
196+
197+
constructor(
198+
// inject "Database"
199+
database: Database
200+
) {
201+
database.query(TestClazz).then(query => {
202+
query
203+
.select(x => x.description)
204+
.where(where => where.equal(x => x.id, 1));
205+
console.log(query.compile());
206+
/**
207+
* {
208+
* params: [1],
209+
* query: "SELECT tes.description AS description FROM TestClazz AS tes WHERE tes.id > ?"
210+
* }
211+
*/
212+
// to execute in database return promise with result
213+
query.toList();
214+
});
215+
}
216+
}
217+
```
218+
219+
[**More documentation on database-builder (Query, Crud, etc)**](https://github.com/fernandocode/database-builder).

0 commit comments

Comments
 (0)