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: writing-adapters.md
+14-7Lines changed: 14 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,23 +7,30 @@ If you want to see an example adapter, check out the default [`flat-file-db` ada
7
7
## Overview
8
8
9
9
The methods every adapter has to have are:
10
+
-`get(key: string): Promise`: Get a value from the database
11
+
-`put(key: string, value: object): Promise`: Put a value into the database
12
+
-`has(key: string): Promise`: Check if the database has a value for a certain key
13
+
-`getAll(options?): Promise`: Get all values from the database as JSON
10
14
11
-
-`get(key: string)`: Get a value from the database
12
-
-`put(key: string, value: object)`: Put a value into the database
13
-
-`has(key: string)`: Check if the database has a value for a certain key
14
-
-`getAll(options?)`: Get all values from the database as JSON
15
+
All of these methods have to return Promises. On top of that there is some optional methods:
15
16
16
-
All of these methods have to return Promises. On top of that there is one more method, which returns an Observer (based on the [proposed spec](https://github.com/tc39/proposal-observable))
17
+
-`init(options: Object): void`: A method to setup the adapter based on
18
+
-`subscribe(pathname?: string): Observer`: Subscribe to changes of all keys starting with a certain `pathname`. If no pathname is provided, subscribe to all changes. It returns an Observer (based on the [proposed spec](https://github.com/tc39/proposal-observable))
17
19
18
-
-`subscribe(pathname?: string)`: Subscribe to changes of all keys starting with a certain `pathname`. If no pathname is provided, subscribe to all changes.
20
+
Furthermore, there are some non callable fields:
21
+
-`options: Array<ArgsOption>`: An array of cli options that is needed to configure the adapter. The elements in the list should be compatible with the options of the [args library][args-options]. It is important to read environment variables and put that in the `defaultValue` field to support configuration through environment variables. The parsed options will be passed to `init` described above, thus, `init` is required when options is defined.
0 commit comments