Skip to content

Commit

Permalink
Update Dexie and other dependencies to latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
philmtd committed Oct 20, 2020
1 parent 774d7f3 commit bea7529
Show file tree
Hide file tree
Showing 7 changed files with 2,216 additions and 2,156 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![CircleCI](https://circleci.com/gh/subshell/data-repositories.svg?style=svg)](https://circleci.com/gh/subshell/data-repositories) [![npm version](https://badge.fury.io/js/%40subshell%2Fdata-repositories.svg)](https://badge.fury.io/js/%40subshell%2Fdata-repositories)

This is a wrapper around [Dexie](https://github.com/dfahlander/Dexie.js), which itself is already a wrapper around IndexedDB. This wrapper allows to create
repositories, similar as you might be used to from Java and Spring Data.
repository classes, similar as you might be used to from Java and Spring Data.

Short example of a repository:

Expand Down Expand Up @@ -52,6 +52,8 @@ You can define a field to be the primary key of the repository by adding `@Id()`
If you want multiple properties to be a compound primary key you can add multiple `@CompoundId()` decorators to those fields. If you are using `@IncrementalId()`
or `@CompoundId()` you need to add an additional generic parameter to the repository, e.g.:

In any case you **must** use one of the `@Id()`, `@CompoundId()` or `@IncrementalId()` decorators in your repository.

```typescript
/*****************************
* Compound ID:
Expand Down Expand Up @@ -82,18 +84,17 @@ class PersonRepository extends AbstractRepository<Person, number> {
To make keys unique you can use `@Unique()` and to have indexed fields (you can only use those in search queries) you need to use `@Indexed()`.
`@CompoundId()` fields are not automatically indexed separately, so if you want to be able to query these you need to additionally add the
`@Indexed()` decorator to them.
Did I say you *can* define a field? Actually you **must** use one of the `@Id()`, `@CompoundId()` or `@IncrementalId()` decorator.

If you should at a later point upgrade your data model and e.g. add a unique or indexed field, you need to specify the respective database version in the decorator,
e.g. `@Unique({sinceVersion: 2})`. Versions start with **1** so if you update your model it is definitely at least version 2.

Methods you can use on repositories are: `save`, `saveAll`, `findById`, `findAll`, `delete`, `clear`, `count`
Methods you can use on repositories are: `save`, `saveAll`, `findById`, `findAll`, `delete`, `clear`, `count`.

Additionally the `AbstractRepository` and `AbstractMappingRepository` allow to search using simple property equality checks and predicates with the `.search()` method.
Additionally, the `AbstractRepository` and `AbstractMappingRepository` allow searching using simple property equality checks and predicates with the `.search()` method.
This functionality is very basic and far from what Dexie actually offers. This is currently a low priority TODO but feel free to contribute.

It is recommended to have separate Dexie databases for every repository (due to some issues with Dexie and the versioning across multiple repositories). Use the `DatabaseAccess` class with care and
try not to create those classes with duplicate names unless you know what you do - you have been warned. Feel free to fix this if having more than one IndexedDB keeps you from sleeping at night.
try not to create those classes with duplicate names unless you know what you do.

The repositories naturally work with RxJS and Observables. If you want to use JavaScript Promises instead you can just call `.toPromise()` on every returned Observable.
Due to the nature of IndexedDB there is no synchronous way to read or write any data.
Due to the nature of IndexedDB there is no synchronous way to read or write any data.
Loading

0 comments on commit bea7529

Please sign in to comment.