SapphireDb logo SapphireDb

Model definition

SapphireDb requires knowledge about the primary keys a model has. By default it is assumed that the primary always is called id. You can configure it by defining a custom model class on client side and configure the collection to use this class type.

sapphiredb-js tries to encourage you to use typed classes for complex models. This ensures a clean client implementation when building applications.
Also check out class transformer if you are using classes for your models on client side.

Custom primary key

\f:(typescript:ts) class CustomClass {\n \t@PrimaryKey()\n \tcustomId: string;\n }\n\n db.collection('example', CustomClass)

Multiple primary keys/Composite primary key

\f:(typescript:ts) class CustomClass2 extends CustomClass {\n \t@PrimaryKey()\n \tsecondId: string;\n }\n\n db.collection('example', CustomClass2)
You can also enrich a class by adding primary keys in a subclass

This website uses Google Analytics. If you want to disable it just unselect the option: