@@ -40,6 +40,7 @@ Package is **free** to use. If you enjoy it, please consider donating via [fiat]
4040* [ Demonstration] ( #demonstration )
4141* [ Skeleton] ( #skeleton )
4242* [ Code scaffolding] ( #code-scaffolding )
43+ * [ Example usage] ( #example-usage )
4344* [ Documentation] ( #documentation )
4445 * [ IDBConnection] ( #idbconnection ) Class to open connection and create object store.
4546 * [ IDBData] ( #idbdata ) Class with opened connection (IDBConnection), to handle transaction and store.
@@ -94,6 +95,125 @@ To get more help on the Angular CLI use `ng help` or go check out the [Angular C
9495
9596<br >
9697
98+ ## Example usage
99+
100+ Prepare configuration.
101+
102+ ``` typescript
103+ // config.ts
104+ import { IndexedDB } from " @angular-package/indexeddb" ;
105+
106+ // Config.
107+ export const IDB_CONFIG = IndexedDB .config ({
108+ name: ' databasename' ,
109+ storeNames: [' storename1' , ' storename2' ],
110+ store: IndexedDB .store ({
111+ ' storename1' : {
112+ keyPath: ' id' ,
113+ autoIncrement: false ,
114+ index: [
115+ { name: " name" , keyPath: " name" , options: { unique: false } },
116+ ]
117+ },
118+ ' storename2' : {
119+ keyPath: " id" ,
120+ autoIncrement: true ,
121+ index: [
122+ { name: " name" , keyPath: " name" , options: { unique: false } },
123+ { name: " position" , keyPath: " position" , options: { unique: false } },
124+ { name: " weight" , keyPath: " weight" , options: { unique: false } },
125+ { name: " symbol" , keyPath: " symbol" , options: { unique: false } },
126+ ],
127+ },
128+ }),
129+ version: 1
130+ });
131+ ```
132+
133+ Use configuration and initialize database.
134+
135+ ``` typescript
136+ // example.ts
137+ import { IndexedDB } from " @angular-package/indexeddb" ;
138+ import { IDB_CONFIG } from ' ./config' ;
139+
140+ // Initialize.
141+ const indexeddb = new IndexedDB <
142+ // Create store interface.
143+ {
144+ storename1 : {
145+ id : number ,
146+ name : string
147+ },
148+ storename2 : {
149+ id : number ,
150+ name : string ,
151+ position : number ,
152+ weight : number ,
153+ symbol : string
154+ }
155+ }
156+ > (
157+ IDB_CONFIG .name ,
158+ IDB_CONFIG .storeNames ,
159+ IDB_CONFIG .store ,
160+ IDB_CONFIG .version
161+ );
162+
163+ // Add by method
164+ indexeddb .query .method ({
165+ ' add' : {
166+ ' storename2' : {
167+ value: {
168+ ' id' : 1 ,
169+ ' name' : ' name' ,
170+ ' position' : 1 ,
171+ ' symbol' : ' N' ,
172+ ' weight' : 100
173+ },
174+ ' onsuccess' : (result ) => console .log (result ),
175+ ' onerror' : (ev ) => console .log (` error ` , ev ),
176+ }
177+ }
178+ })
179+
180+ // Get
181+ indexeddb .query .method ({
182+ ' get' : {
183+ ' storename2' : {
184+ ' query' : 1 ,
185+ ' onsuccess' : (result => console .log (result )),
186+ ' onerror' : () => console .log (` error ` )
187+ },
188+ }
189+ });
190+
191+ // Add by store
192+ indexeddb .query .store ({
193+ ' storename1' : {
194+ ' add' : {
195+ ' value' : {
196+ ' id' : 2 ,
197+ ' name' : ' item'
198+ },
199+ ' onsuccess' : (result ) => console .log (result )
200+ }
201+ }
202+ })
203+
204+ // Get
205+ indexeddb .query .store ({
206+ ' storename1' : {
207+ ' get' : {
208+ ' query' : 2 ,
209+ ' onsuccess' : result => console .log (result )
210+ }
211+ }
212+ })
213+ ```
214+
215+ <br >
216+
97217## Documentation
98218
99219The documentation is in construction and it's available at [ https://angular-package.gitbook.io/indexedb ] ( https://angular-package.gitbook.io/indexedb )
@@ -102,49 +222,150 @@ The documentation is in construction and it's available at [https://angular-pack
102222
103223Class to open connection and create object store.
104224
225+ ``` typescript
226+ export class IDBConnection <
227+ Name extends string = string ,
228+ StoreNames extends string | number | symbol = string ,
229+ Version extends number = number
230+ > { ... }
231+ ```
232+
105233[ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb-connection.class.ts )
106234
107235### IDBData
108236
109237Class with opened connection (IDBConnection), to handle transaction and store.
110238
239+ ``` typescript
240+ export class IDBData <
241+ Name extends string = string ,
242+ StoreNames extends string | number | symbol = string ,
243+ Version extends number = number ,
244+ > { ... }
245+ ```
246+
111247[ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb-data.class.ts )
112248
113249### IDBQuery
114250
115251Query store with JSON, by method-store or store-method.
116252
253+ ``` typescript
254+ export class IDBQuery <
255+ StoreSchema extends object ,
256+ Name extends string = string ,
257+ StoreNames extends keyof StoreSchema = keyof StoreSchema ,
258+ Version extends number = number
259+ > { ... }
260+ ```
261+
117262[ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb-query.class.ts )
118263
119264### IDBStore
120265
121266Store methods with database connection (IDBData).
122267
268+ ``` typescript
269+ export class IDBStore <
270+ StoreSchema extends object ,
271+ Name extends string = string ,
272+ StoreNames extends keyof StoreSchema = keyof StoreSchema ,
273+ Version extends number = number ,
274+ > implements IDBStoreInterface <StoreSchema , StoreNames > {
275+ ...
276+ }
277+ ```
278+
123279[ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb-store.class.ts )
124280
125281### IDBConfig
126282
127283IDB configuration used in Angular IDBModule.
128284
129- [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb-config.class.ts )
285+ ``` typescript
286+ export class IDBConfig <
287+ Name extends string = string ,
288+ StoreNames extends string | number | symbol = string ,
289+ Version extends number = number
290+ > {
291+ name? : Name ;
292+ storeNames? : StoreNames | StoreNames [];
293+ store? : IDBStoreParameters <StoreNames >;
294+ version? : Version ;
295+ };
296+ ```
297+
298+ [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb.config.ts )
130299
131300### IDBModule
132301
133302Angular Module with indexeddb service.
134303
135- [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb-module.class.ts )
304+ ``` typescript
305+ @NgModule ({
306+ declarations: [],
307+ imports: [
308+ CommonModule
309+ ]
310+ })
311+ export class IDBModule {
312+ static forRoot(@Optional () @Inject (IDBConfig ) config ? : IDBConfig ): ModuleWithProviders <IDBModule > {
313+ return {
314+ ngModule: IDBModule ,
315+ providers: [
316+ IDBService ,
317+ {provide: IDBConfig , useValue: config , multi: false }
318+ ]
319+ }
320+ }
321+ static forChild(@Optional () @Inject (IDBConfig ) config : IDBConfig ): ModuleWithProviders <IDBModule > {
322+ return {
323+ ngModule: IDBModule ,
324+ providers: [
325+ IDBService ,
326+ {provide: IDBConfig , useValue: config , multi: false }
327+ ]
328+ };
329+ }
330+ }
331+ ```
332+
333+ [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb.module.ts )
136334
137335### IDBService
138336
139337Angular Service with IndexedDB class.
140338
141- [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb-service.class.ts )
339+ ``` typescript
340+ @Injectable ({
341+ providedIn: " root" ,
342+ })
343+ export class IDBService <
344+ StoreSchema extends object ,
345+ Name extends string = string ,
346+ StoreNames extends keyof StoreSchema = keyof StoreSchema ,
347+ Version extends number = number
348+ > {
349+ ...
350+ }
351+ ```
352+
353+ [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/idb.service.ts )
142354
143355### IndexedDB
144356
145357Store and query for IndexedDB client-side storage.
146358
147- [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/indexeddb.class.ts )
359+ ``` typescript
360+ export class IndexedDB <
361+ StoreSchema extends object ,
362+ Name extends string = string ,
363+ StoreNames extends keyof StoreSchema = keyof StoreSchema ,
364+ Version extends number = number
365+ > { ... }
366+ ```
367+
368+ [ GitHub] ( https://github.com/angular-package/indexeddb/blob/main/src/lib/indexeddb.ts )
148369
149370<br >
150371
0 commit comments