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
docs: show custom storage driver from interface, not wrap
Address review feedback: from-scratch drivers implement the unstorage interface; wrapping is only for patching existing drivers.
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: docs/1.docs/8.storage.md
+33-14Lines changed: 33 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,42 +105,61 @@ You can find the driver list on [unstorage documentation](https://unstorage.unjs
105
105
106
106
The `driver` field accepts a built-in driver name (for example `"redis"`) or a **path** to a custom driver module. You cannot pass a driver function or object directly in config — Nitro imports drivers as separate modules so your config stays separate from runtime code.
107
107
108
-
Create a driver file that default-exports a driver created with`defineDriver`:
108
+
Create a driver file that **default-exports** a driver factory from`defineDriver`. To build a driver from scratch, implement the [unstorage driver interface](https://unstorage.unjs.io/guide/custom-driver) (`hasItem`, `getItem`, `setItem`, and so on):
Reference it by path in your Nitro config (options besides `driver` are passed into the factory):
127
145
128
146
```ts [nitro.config.ts]
129
147
import { defineConfig } from"nitro";
130
148
131
149
exportdefaultdefineConfig({
132
150
storage: {
133
-
upstash: {
134
-
driver: "./drivers/upstash.ts",
135
-
url: process.env.KV_REST_API_URL,
136
-
token: process.env.KV_REST_API_TOKEN,
151
+
kv: {
152
+
driver: "./drivers/kv.ts",
153
+
prefix: "app:",
137
154
},
138
155
},
139
156
});
140
157
```
141
158
142
159
Use a path relative to your project root (or an absolute path). Nitro bundles the driver for the server runtime.
143
160
161
+
To **patch** an existing unstorage driver instead of writing one from scratch, wrap it inside `defineDriver`, spread the base driver, and override only the methods you need.
0 commit comments