You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65Lines changed: 65 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -486,7 +486,72 @@ import { SavedData } from 'springroll-container';
486
486
// Firstly, construct the SavedData object. This is only needed for IndexedDB work
487
487
savedData =newSavedData('dbName');
488
488
489
+
// Then, open a connection to the database. All changes to the structure of the database should be passed in here
489
490
```
491
+
Additions is an optional parameter expecting a JSON object with any additions to the databases structure namely new [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/createObjectStore) and [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex). These are placed inside of an array
492
+
493
+
Deletions is an optional parameter used to delete any [indexes](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/deleteIndex) or [stores](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore)
494
+
495
+
```javascript
496
+
497
+
let additions = {
498
+
stores: [{
499
+
storeName:'storeOne',
500
+
// optionally define a keyPath and/or set autoIncrement to true or false
501
+
options: { keyPath:"taskTitle" }
502
+
},
503
+
{
504
+
storeName:'storeTwo'
505
+
}],
506
+
indexes: [{
507
+
indexName:'newIndex',
508
+
keyPath:'key',
509
+
// Any objectParameters for the Index
510
+
options: {
511
+
unique:false
512
+
}
513
+
}]
514
+
};
515
+
516
+
// Deletions is an optional parameter used to delete any indexes or stores
517
+
let deletions = {
518
+
stores: ['storeOne', 'storeTwo'],
519
+
indexes: ['newIndex']
520
+
};
521
+
522
+
// Optionally pass in the new database version. Set to true to increment the database version.
523
+
// Leave this parameter out or pass in false to connect without making any changes to the structure of the database
524
+
let dbVersion =1
525
+
526
+
// The name of the database to connect to
527
+
let dbName ='dbName';
528
+
529
+
// Finally, pass these parameters in to establish a connection with the database
There are other methods currently supported to interact with the database. These allow you to [Add a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/add), [Deleting a record](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/delete), [Reading](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/get), [reading all records](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/getAll) Each will return a success, or on failure, an error message
534
+
535
+
```javascript
536
+
537
+
//Delete a record by the key in a specific store
538
+
savedData.IDBRemove('storeName', 'key');
539
+
540
+
// add a record to a store. The record can be any type of object accepted by indexedDB
541
+
savedData.IDBAdd('storeName', 'record');
542
+
543
+
// returns the record with the given key from the store with the given storeName
544
+
savedData.IDBRead('storeName', 'key');
545
+
546
+
// Finally, close the connection to the database
547
+
savedData.closeDb();
548
+
549
+
// Return all records from a database or optionally a specified amount defined by the second parameter
550
+
savedData.IDBReadAll('storeName');
551
+
savedData.IDBReadAll('storeName', 5);
552
+
553
+
554
+
490
555
All other methods will work the same as the documentation [here](https://github.com/SpringRoll/SpringRoll/tree/main/src/state#userdata);
0 commit comments