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
By default, all tables in your Drizzle schema are exposed through the API. You can restrict the tables that are exposed by using the `allowTables` function.
156
+
157
+
::: tip
158
+
Put this code in a Nitro plugin in `server/plugins` so it's executed once when the server starts.
159
+
:::
160
+
161
+
```ts
162
+
import*astablesfrom'path-to-your-drizzle-schema'
163
+
164
+
exportdefaultdefineNitroPlugin(() => {
165
+
allowTables([
166
+
tables.todos,
167
+
])
168
+
})
169
+
```
170
+
171
+
Any table that is not explicitly listed will throw on all API endpoints. `allowTables` can be called multiple times, and the allowed tables will be merged.
172
+
153
173
## Hooks
154
174
155
-
You can use hooks to run code before or after certain actions on the collections. You can register global hooks for all collections using the `rstoreDrizzleHooks` import, or specific hooks for a given table using the `hooksForTable` function.
175
+
You can use hooks to run code before or after certain actions on the collections. You can register global hooks for all collections using the `rstoreDrizzleHooks` import, or specific hooks for a given table using the `hooksForTable` function (recommended).
176
+
177
+
::: tip
178
+
Put this code in a Nitro plugin in `server/plugins` so it's executed once when the server starts.
179
+
:::
156
180
157
181
You can use the following hooks:
158
182
@@ -169,6 +193,28 @@ You can use the following hooks:
169
193
170
194
If you throw an error in a `before` hook, the action will be aborted and the error will be returned to the client.
171
195
196
+
```ts
197
+
import*astablesfrom'path-to-your-drizzle-schema'
198
+
199
+
exportdefaultdefineNitroPlugin(() => {
200
+
hooksForTable(tables.todos, {
201
+
'index.get.before': async (payload) => {
202
+
console.log('Specific hook for todos - index.get.before', payload.collection, payload.query, payload.params)
203
+
},
204
+
'index.get.after': async (payload) => {
205
+
console.log('Specific hook for todos - index.get.after', payload.collection, payload.result.map(r=>r.id))
206
+
},
207
+
'item.patch.after': async (payload) => {
208
+
console.log('Specific hook for todos - item.patch.after', payload.collection, payload.result.id)
209
+
},
210
+
})
211
+
})
212
+
```
213
+
214
+
<details>
215
+
216
+
<summary>You can also register global hooks for all tables.</summary>
0 commit comments