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: docs/content/docs/extend/custom_lock_store.md
+76-4Lines changed: 76 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,81 @@ const verrou = new Verrou({
41
41
})
42
42
```
43
43
44
+
## Create an adapter for the DatabaseStore
45
+
46
+
If your want to use a database to store your locks, you are not forced to create a full driver. You can leverage the adapter system available in the database store.
47
+
48
+
We only ship adapter for Kysely and Knex to interact with the database for now. If ever you want to use another library, you can create your own adapter by implementing the `DatabaseAdapter` interface accessible from `@verrou/core/types`. The interface is defined as follows:
49
+
50
+
```ts
51
+
exportinterfaceDatabaseAdapter {
52
+
/**
53
+
* Set the table name to store the locks
54
+
*/
55
+
setTableName(tableName:string):void
56
+
57
+
/**
58
+
* Create the table to store the locks if it doesn't exist
You can take a look at the code of the [Kysely adapter](https://github.com/Julien-R44/verrou/blob/main/packages/verrou/src/drivers/kysely.ts#L22) or the [Knex adapter](https://github.com/Julien-R44/verrou/blob/main/packages/verrou/src/drivers/kysely.ts#L22) for inspiration.
98
+
99
+
Once you defined your adapter, you can create your own store that use the DatabaseStore and your adapter:
If you want to test your driver and its compliance, Verrou is shipped with a test suite for [Japa](https://japa.dev/docs) that you can use. Note that you will also need to have `@japa/assert` installed. Then, you can use it like this:
@@ -54,10 +129,7 @@ import { registerStoreTestSuite } from '@verrou/core/test_suite'
0 commit comments