Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit b7653ba

Browse files
authored
docs(options): Adds some important notes about design decisions.
1 parent d2fc2c2 commit b7653ba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docs/options.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ The [facade](./facade.md) [functions](./functions.md) have some common options t
1010
- [Pagination](#pagination)
1111

1212
### Id
13-
This is a string that uniquely identifies an entity.
13+
This is a string that uniquely identifies an entity. In some databases the identifier for an entity may actually be stored as a different data type (e.g. a number or MongoId), but the Facade functions will always convert this to a string for compatibility across database implementations.
14+
15+
It's important to know that these identifiers are user-defined, meaning that they will not be generated by the database. The reason for this is that allowing the user to define the identifier enables optimistic updates to be handled more easily especially on the client-side. Frameworks and libraries like Meteor also work in this way.
16+
17+
Having said all of that, there may be ways to allow the database to generate the identifiers in concrete implementations of the Facade, but only when you can specify `constructDocument` and `constructEntity` properties in the factory of those implementations. [The Knex implementation of the Facade](https://github.com/js-entity-repos/knex/blob/master/readme.md) is an example of a concrete implementation that allows you to specify these properties in its factory.
1418

1519
### Entity
1620
This is an object that contains all of the entity's properties. The word "entity" has been borrowed from [Entity-Relationship Models/Diagrams](https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model) and has been used instead of the word "model" to avoid confusion with MVC.
1721

18-
This interface is user-defined hence not contained in this package, the interface below demonstrates what this might look like for a todo entity and extends the [TypeScript Entity interface](../src/types/Entity.ts) defined in this package which contains the `id` property.
22+
This interface is user-defined hence not contained in this package, the interface below demonstrates what this might look like for a todo entity and extends the [TypeScript Entity interface](../src/types/Entity.ts) defined in this package. Note that the Entity interface already contains the [`id`](#id) property.
23+
24+
When using JS-Entity-Repos all entities should have a single unique identifier (the [`id`](#id) property) because the Facade functions do not support composite keys. There are a number of pros and cons to this that you can discover with a little Googling, but be aware that some databases actually enforce a single identifier anyway (such as Mongo). The main reason composite keys are not supported here is that it simplifies routing in HTTP implementations of the Facade such as [Axios](https://github.com/js-entity-repos/axios) and [Express](https://github.com/js-entity-repos/express).
1925

2026
```ts
2127
import Entity from '@js-entity-repos/core/dist/types/Entity';

0 commit comments

Comments
 (0)