Persistence Adapters

Choose or write your own persistence adapter for full control on how the data will be saved

By default, if not explicitly stated, the database will use no persistence layer, all the data will live solely in memory and will be lost once you exit the application or database instance is lost or deleted. This behavior might be what you want. Yet, most of the use cases for the database involve some form of data persistence.

TyDB doesn't rely on one form of database persistence, rather it introduces the concept of pluggable persistence adapter. Since the database might be used in different environment and for different use cases, different adapter have been written. And you would "plug" the adapter that best suits your need. So, when running in the browser, you may want to use the IndexedDB adapter, and when running in NodeJS you may want to use the File system adapter.

Different adapter for different needs and environments

File System persistence adapter

Read more about the file system persistence

IndexedDB persistence adapter

Read more about the browser and IndexedDB persistence

Note: in case that the instance is connecting to another instance over the network (i.e. has a ref like this: tydb://http://localhost:3000/mydb), the persistence_adapter parameter will be ignore (like all other parameters, other than ref & model) and it will act like a shell only responsible for sending arguments and receiving data. The persistence defined in the network database configuration will actually be use.

Read More about over-the-network instances.

Write your own persistence adapter

Writing and plugging your own persistence adapter is fairly easy, start by extending the persistence class and overwrite some methods like the example below

For more elaborate example checkout the adapter that are shipped with the database on github.

Last updated

Was this helpful?