void 0.1.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT_PROMPT.md +15 -0
- package/README.md +62 -123
- package/dist/auth-BdsJ0Aff.d.mts +43 -0
- package/dist/auth-cmd-Dx8oPKZC.mjs +43 -0
- package/dist/auth-migrations-BAtAck2g.mjs +117 -0
- package/dist/better-auth-shared-C9_GHSkR.d.mts +71 -0
- package/dist/better-auth-shared-CdYmQGry.mjs +163 -0
- package/dist/cache-W82I8ihI.mjs +47 -0
- package/dist/cancel-deploy-BOBTqqh0.mjs +59 -0
- package/dist/cf-access-Dee5cXxL.mjs +22 -0
- package/dist/chunk-DJd-R1mw.mjs +34 -0
- package/dist/cli/cli.d.mts +1 -0
- package/dist/cli/cli.mjs +1807 -0
- package/dist/client-snXOjrp1.mjs +565 -0
- package/dist/collect-CjeZgz5D.mjs +55 -0
- package/dist/config-BIa9HwVX.mjs +573 -0
- package/dist/config-BzM9Dy7T.mjs +37 -0
- package/dist/config-CvHtTM0q.mjs +30 -0
- package/dist/create-project-BIA15W7z.mjs +90 -0
- package/dist/db-DsRoMcfN.mjs +895 -0
- package/dist/defer-DcxEsVH1.mjs +49 -0
- package/dist/delete-DAP6yDc7.mjs +64 -0
- package/dist/deploy-BPKblFx6.mjs +2424 -0
- package/dist/discover-B7FkXBLB.mjs +40 -0
- package/dist/dist-DUyXJLkq.mjs +2667 -0
- package/dist/dist-Dayj3gCK.mjs +1287 -0
- package/dist/domain-BGofcQ6I.mjs +79 -0
- package/dist/dotenv-DwO4ti0Z.mjs +173 -0
- package/dist/drizzle-NnudE_UN.mjs +232 -0
- package/dist/env-CyG3tvU0.mjs +301 -0
- package/dist/env-helpers-Dr9Y7RnE.d.mts +52 -0
- package/dist/env-raw-BDL4TvdN.mjs +32 -0
- package/dist/env-types-DknSA4SO.mjs +64 -0
- package/dist/env-validation-DJKjR_8q.mjs +163 -0
- package/dist/fetch-error-BQ8sZ5Nd.mjs +266 -0
- package/dist/fetch-error-CVZ5CGA-.d.mts +20 -0
- package/dist/gen-U0Ktr4Zd.mjs +761 -0
- package/dist/handler-B0ds0OHJ.d.mts +269 -0
- package/dist/head-P-egrtFE.d.mts +45 -0
- package/dist/headers-DCXc7mDs.mjs +279 -0
- package/dist/index.d.mts +32 -0
- package/dist/index.mjs +4695 -0
- package/dist/init-C7wS5iGP.mjs +2625 -0
- package/dist/link-p2R6NbgN.mjs +49 -0
- package/dist/list-Bfel-QLc.mjs +113 -0
- package/dist/log-DXdqnmhF.mjs +26 -0
- package/dist/login-CkcXUiIu.mjs +72 -0
- package/dist/logs-DmkrRvx6.mjs +98 -0
- package/dist/magic-string.es-D6g9UnIy.mjs +1011 -0
- package/dist/mcp-CaQzfeUi.mjs +373 -0
- package/dist/node-DDfXj10V.mjs +54 -0
- package/dist/output-BwlcIYSR.mjs +139 -0
- package/dist/pages/client.d.mts +198 -0
- package/dist/pages/client.mjs +980 -0
- package/dist/pages/head-client.d.mts +15 -0
- package/dist/pages/head-client.mjs +90 -0
- package/dist/pages/head.d.mts +2 -0
- package/dist/pages/head.mjs +112 -0
- package/dist/pages/index.d.mts +38 -0
- package/dist/pages/index.mjs +76 -0
- package/dist/pages/islands-plugin.d.mts +50 -0
- package/dist/pages/islands-plugin.mjs +195 -0
- package/dist/pages/prefetch.d.mts +31 -0
- package/dist/pages/prefetch.mjs +90 -0
- package/dist/pages/protocol.d.mts +3 -0
- package/dist/pages/protocol.mjs +193 -0
- package/dist/pages/serialize.d.mts +10 -0
- package/dist/pages/serialize.mjs +14 -0
- package/dist/pathe.M-eThtNZ-D-kmWkCS.mjs +150 -0
- package/dist/plugin-inference-oZ6Ybu2_.mjs +2447 -0
- package/dist/prepare-BAtWufvm.mjs +99 -0
- package/dist/preset-D4I73kT4.mjs +221 -0
- package/dist/project-TqORyHn8.mjs +72 -0
- package/dist/project-cmd-B7lQp3F3.mjs +67 -0
- package/dist/project-slug-CKam8lF9.mjs +11 -0
- package/dist/project-tsconfig-DfkESbDL.mjs +63 -0
- package/dist/protocol-BWzXs2A2.d.mts +34 -0
- package/dist/providers-B3aMxWzP.mjs +67 -0
- package/dist/resolve-project-Br5BR03U.mjs +29 -0
- package/dist/rollback-gyC59l7U.mjs +92 -0
- package/dist/route-types-DReF1gUY.mjs +255 -0
- package/dist/routes-stub.d.mts +55 -0
- package/dist/routes-stub.mjs +1 -0
- package/dist/runner-6Ep3fNQu.mjs +123 -0
- package/dist/runner-pg-D0wWHYnr.mjs +57 -0
- package/dist/runtime/ai.d.mts +127 -0
- package/dist/runtime/ai.mjs +348 -0
- package/dist/runtime/auth-client-react.d.mts +8 -0
- package/dist/runtime/auth-client-react.mjs +6 -0
- package/dist/runtime/auth-client-solid.d.mts +8 -0
- package/dist/runtime/auth-client-solid.mjs +6 -0
- package/dist/runtime/auth-client-svelte.d.mts +8 -0
- package/dist/runtime/auth-client-svelte.mjs +6 -0
- package/dist/runtime/auth-client-vue.d.mts +8 -0
- package/dist/runtime/auth-client-vue.mjs +6 -0
- package/dist/runtime/auth-client.d.mts +8 -0
- package/dist/runtime/auth-client.mjs +6 -0
- package/dist/runtime/auth.d.mts +2 -0
- package/dist/runtime/auth.mjs +22 -0
- package/dist/runtime/better-auth-pg.d.mts +11 -0
- package/dist/runtime/better-auth-pg.mjs +51 -0
- package/dist/runtime/better-auth.d.mts +11 -0
- package/dist/runtime/better-auth.mjs +33 -0
- package/dist/runtime/client.d.mts +6 -0
- package/dist/runtime/client.mjs +5 -0
- package/dist/runtime/db-pg.d.mts +2 -0
- package/dist/runtime/db-pg.mjs +1 -0
- package/dist/runtime/db.d.mts +17 -0
- package/dist/runtime/db.mjs +30 -0
- package/dist/runtime/drizzle-arktype.d.mts +1 -0
- package/dist/runtime/drizzle-arktype.mjs +2 -0
- package/dist/runtime/drizzle-valibot.d.mts +1 -0
- package/dist/runtime/drizzle-valibot.mjs +2 -0
- package/dist/runtime/drizzle-zod.d.mts +1 -0
- package/dist/runtime/drizzle-zod.mjs +2 -0
- package/dist/runtime/env-helpers.d.mts +2 -0
- package/dist/runtime/env-helpers.mjs +173 -0
- package/dist/runtime/env-public-client.d.mts +22 -0
- package/dist/runtime/env-public-client.mjs +54 -0
- package/dist/runtime/env-public.d.mts +143 -0
- package/dist/runtime/env-public.mjs +366 -0
- package/dist/runtime/env.d.mts +13 -0
- package/dist/runtime/env.mjs +51 -0
- package/dist/runtime/fetch-stream.d.mts +51 -0
- package/dist/runtime/fetch-stream.mjs +81 -0
- package/dist/runtime/fetch.d.mts +59 -0
- package/dist/runtime/fetch.mjs +18 -0
- package/dist/runtime/handler.d.mts +3 -0
- package/dist/runtime/handler.mjs +85 -0
- package/dist/runtime/isr.d.mts +26 -0
- package/dist/runtime/isr.mjs +43 -0
- package/dist/runtime/kv.d.mts +48 -0
- package/dist/runtime/kv.mjs +106 -0
- package/dist/runtime/log.d.mts +24 -0
- package/dist/runtime/log.mjs +31 -0
- package/dist/runtime/migration-handler-pg.d.mts +6 -0
- package/dist/runtime/migration-handler-pg.mjs +85 -0
- package/dist/runtime/migration-handler.d.mts +19 -0
- package/dist/runtime/migration-handler.mjs +92 -0
- package/dist/runtime/queues.d.mts +7 -0
- package/dist/runtime/queues.mjs +8 -0
- package/dist/runtime/remote/binding-handler.d.mts +15 -0
- package/dist/runtime/remote/binding-handler.mjs +208 -0
- package/dist/runtime/remote/index.d.mts +8 -0
- package/dist/runtime/remote/index.mjs +461 -0
- package/dist/runtime/response.d.mts +14 -0
- package/dist/runtime/response.mjs +30 -0
- package/dist/runtime/sandbox.d.mts +17 -0
- package/dist/runtime/sandbox.mjs +19 -0
- package/dist/runtime/schema-d1.d.mts +1 -0
- package/dist/runtime/schema-d1.mjs +2 -0
- package/dist/runtime/schema-pg.d.mts +1 -0
- package/dist/runtime/schema-pg.mjs +2 -0
- package/dist/runtime/seed.d.mts +30 -0
- package/dist/runtime/seed.mjs +6 -0
- package/dist/runtime/storage.d.mts +7 -0
- package/dist/runtime/storage.mjs +14 -0
- package/dist/runtime/validator.d.mts +2 -0
- package/dist/runtime/validator.mjs +72 -0
- package/dist/runtime/ws-server.d.mts +26 -0
- package/dist/runtime/ws-server.mjs +296 -0
- package/dist/runtime/ws.d.mts +123 -0
- package/dist/runtime/ws.mjs +103 -0
- package/dist/scan-Ba4hFwlH.mjs +324 -0
- package/dist/scan-C6HMEIdW.mjs +318 -0
- package/dist/secret-CeRSukgM.mjs +109 -0
- package/dist/skills-ipldjlKE.mjs +62 -0
- package/dist/standard-schema-9CRjx-uR.d.mts +42 -0
- package/dist/subcommand-prompt-BKjuNAPb.mjs +349 -0
- package/dist/sveltekit.d.mts +20 -0
- package/dist/sveltekit.mjs +61 -0
- package/dist/types-mHOEwpW4.d.mts +57 -0
- package/dist/validate-CaMavMxu.mjs +146 -0
- package/dist/yarn-pnp-BFqMV_bl.mjs +196 -0
- package/getting-started-prompt.txt +26 -0
- package/package.json +322 -30
- package/schema.json +364 -0
- package/skills/migrate-vite-cloudflare-to-void/SKILL.md +175 -0
- package/skills/void/SKILL.md +75 -0
- package/skills/void/command/void.md +7 -0
- package/skills/void/docs/guide/ai.md +235 -0
- package/skills/void/docs/guide/app-types.md +103 -0
- package/skills/void/docs/guide/auth.md +257 -0
- package/skills/void/docs/guide/database/d1.md +106 -0
- package/skills/void/docs/guide/database/postgresql.md +106 -0
- package/skills/void/docs/guide/database.md +418 -0
- package/skills/void/docs/guide/deployment.md +98 -0
- package/skills/void/docs/guide/edge/headers.md +79 -0
- package/skills/void/docs/guide/edge/prerendering.md +83 -0
- package/skills/void/docs/guide/edge/redirects.md +116 -0
- package/skills/void/docs/guide/edge/revalidation.md +131 -0
- package/skills/void/docs/guide/edge/rewrites.md +354 -0
- package/skills/void/docs/guide/edge/static-assets.md +72 -0
- package/skills/void/docs/guide/env-vars.md +298 -0
- package/skills/void/docs/guide/index.md +80 -0
- package/skills/void/docs/guide/jobs.md +91 -0
- package/skills/void/docs/guide/kv.md +107 -0
- package/skills/void/docs/guide/pages-routing/actions-and-forms.md +419 -0
- package/skills/void/docs/guide/pages-routing/head.md +130 -0
- package/skills/void/docs/guide/pages-routing/islands.md +405 -0
- package/skills/void/docs/guide/pages-routing/layouts.md +362 -0
- package/skills/void/docs/guide/pages-routing/loaders.md +267 -0
- package/skills/void/docs/guide/pages-routing/markdown.md +625 -0
- package/skills/void/docs/guide/pages-routing/overview.md +236 -0
- package/skills/void/docs/guide/pages-routing/view-transitions.md +140 -0
- package/skills/void/docs/guide/queues.md +140 -0
- package/skills/void/docs/guide/quickstart.md +233 -0
- package/skills/void/docs/guide/remote-dev.md +67 -0
- package/skills/void/docs/guide/sandboxes.md +82 -0
- package/skills/void/docs/guide/server-routing.md +246 -0
- package/skills/void/docs/guide/ssg.md +74 -0
- package/skills/void/docs/guide/ssr.md +105 -0
- package/skills/void/docs/guide/storage.md +67 -0
- package/skills/void/docs/guide/type-safety.md +179 -0
- package/skills/void/docs/guide/typed-fetch.md +113 -0
- package/skills/void/docs/guide/websockets.md +190 -0
- package/skills/void/docs/index.md +48 -0
- package/skills/void/docs/integrations/agents.md +84 -0
- package/skills/void/docs/integrations/cloudflare.md +284 -0
- package/skills/void/docs/integrations/frameworks/analog.md +182 -0
- package/skills/void/docs/integrations/frameworks/astro.md +197 -0
- package/skills/void/docs/integrations/frameworks/nuxt.md +164 -0
- package/skills/void/docs/integrations/frameworks/overview.md +136 -0
- package/skills/void/docs/integrations/frameworks/react-router.md +137 -0
- package/skills/void/docs/integrations/frameworks/sveltekit.md +191 -0
- package/skills/void/docs/integrations/frameworks/tanstack-start.md +140 -0
- package/skills/void/docs/integrations/hono.md +97 -0
- package/skills/void/docs/integrations/nodejs-bun-deno.md +210 -0
- package/skills/void/docs/node_modules/@iconify/vue/README.md +408 -0
- package/skills/void/docs/node_modules/@iconify/vue/offline/readme.md +5 -0
- package/skills/void/docs/node_modules/@voidzero-dev/vitepress-theme/README.md +103 -0
- package/skills/void/docs/node_modules/oxc-minify/README.md +78 -0
- package/skills/void/docs/node_modules/reka-ui/README.md +80 -0
- package/skills/void/docs/node_modules/vitepress/README.md +28 -0
- package/skills/void/docs/node_modules/vitepress/template/api-examples.md +49 -0
- package/skills/void/docs/node_modules/vitepress/template/index.md +28 -0
- package/skills/void/docs/node_modules/vitepress/template/markdown-examples.md +85 -0
- package/skills/void/docs/node_modules/vitepress-plugin-group-icons/README.md +101 -0
- package/skills/void/docs/node_modules/void/AGENTS.md +204 -0
- package/skills/void/docs/node_modules/void/AGENT_PROMPT.md +15 -0
- package/skills/void/docs/node_modules/void/README.md +89 -0
- package/skills/void/docs/node_modules/void/node_modules/@clack/prompts/CHANGELOG.md +591 -0
- package/skills/void/docs/node_modules/void/node_modules/@clack/prompts/README.md +375 -0
- package/skills/void/docs/node_modules/void/node_modules/@cloudflare/sandbox/README.md +174 -0
- package/skills/void/docs/node_modules/void/node_modules/@cloudflare/vite-plugin/README.md +37 -0
- package/skills/void/docs/node_modules/void/node_modules/@cloudflare/workers-types/README.md +135 -0
- package/skills/void/docs/node_modules/void/node_modules/@electric-sql/pglite/README.md +189 -0
- package/skills/void/docs/node_modules/void/node_modules/@hono/oauth-providers/CHANGELOG.md +143 -0
- package/skills/void/docs/node_modules/void/node_modules/@hono/oauth-providers/README.md +1272 -0
- package/skills/void/docs/node_modules/void/node_modules/@napi-rs/keyring/README.md +19 -0
- package/skills/void/docs/node_modules/void/node_modules/@types/better-sqlite3/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@types/node/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@types/pg/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@typescript/native-preview/README.md +22 -0
- package/skills/void/docs/node_modules/void/node_modules/@typescript/native-preview/vendor/vscode-jsonrpc/README.md +69 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/README.md +152 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/@shikijs/engine-javascript/README.md +9 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/@shikijs/transformers/README.md +9 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/@types/node/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/gray-matter/CHANGELOG.md +24 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/gray-matter/README.md +565 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-exit/README.md +124 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-anchor/README.md +600 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-attrs/README.md +386 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-container/README.md +95 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/markdown-it-emoji/README.md +101 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/pathe/README.md +73 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/shiki/README.md +15 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/tinyglobby/README.md +25 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/tsdown/README.md +55 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/vite/LICENSE.md +2230 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/vite/README.md +20 -0
- package/skills/void/docs/node_modules/void/node_modules/@void/md/node_modules/vue/README.md +58 -0
- package/skills/void/docs/node_modules/void/node_modules/arktype/README.md +165 -0
- package/skills/void/docs/node_modules/void/node_modules/better-auth/LICENSE.md +20 -0
- package/skills/void/docs/node_modules/void/node_modules/better-auth/README.md +32 -0
- package/skills/void/docs/node_modules/void/node_modules/better-sqlite3/README.md +99 -0
- package/skills/void/docs/node_modules/void/node_modules/blake3-jit/README.md +108 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-arktype/README.md +51 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-kit/README.md +79 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-orm/README.md +44 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-valibot/README.md +51 -0
- package/skills/void/docs/node_modules/void/node_modules/drizzle-zod/README.md +65 -0
- package/skills/void/docs/node_modules/void/node_modules/es-module-lexer/README.md +390 -0
- package/skills/void/docs/node_modules/void/node_modules/estree-walker/README.md +48 -0
- package/skills/void/docs/node_modules/void/node_modules/hono/README.md +85 -0
- package/skills/void/docs/node_modules/void/node_modules/ignore/README.md +452 -0
- package/skills/void/docs/node_modules/void/node_modules/jsonc-parser/CHANGELOG.md +76 -0
- package/{LICENSE → skills/void/docs/node_modules/void/node_modules/jsonc-parser/LICENSE.md} +21 -21
- package/skills/void/docs/node_modules/void/node_modules/jsonc-parser/README.md +364 -0
- package/skills/void/docs/node_modules/void/node_modules/jsonc-parser/SECURITY.md +41 -0
- package/skills/void/docs/node_modules/void/node_modules/magic-string/README.md +325 -0
- package/skills/void/docs/node_modules/void/node_modules/ofetch/README.md +398 -0
- package/skills/void/docs/node_modules/void/node_modules/pathe/README.md +73 -0
- package/skills/void/docs/node_modules/void/node_modules/pg/README.md +95 -0
- package/skills/void/docs/node_modules/void/node_modules/pglite-server/LICENSE.md +21 -0
- package/skills/void/docs/node_modules/void/node_modules/pglite-server/README.md +135 -0
- package/skills/void/docs/node_modules/void/node_modules/picocolors/README.md +21 -0
- package/skills/void/docs/node_modules/void/node_modules/tinyglobby/README.md +25 -0
- package/skills/void/docs/node_modules/void/node_modules/tsdown/README.md +55 -0
- package/skills/void/docs/node_modules/void/node_modules/valibot/LICENSE.md +9 -0
- package/skills/void/docs/node_modules/void/node_modules/valibot/README.md +94 -0
- package/skills/void/docs/node_modules/void/node_modules/vite/LICENSE.md +2230 -0
- package/skills/void/docs/node_modules/void/node_modules/vite/README.md +20 -0
- package/skills/void/docs/node_modules/void/node_modules/wrangler/README.md +63 -0
- package/skills/void/docs/node_modules/void/node_modules/zod/README.md +191 -0
- package/skills/void/docs/node_modules/void/skills/migrate-vite-cloudflare-to-void/SKILL.md +175 -0
- package/skills/void/docs/node_modules/void/skills/void/SKILL.md +75 -0
- package/skills/void/docs/node_modules/void/skills/void/command/void.md +7 -0
- package/skills/void/docs/reference/api.md +917 -0
- package/skills/void/docs/reference/cli.md +561 -0
- package/skills/void/docs/reference/config.md +408 -0
- package/skills/void/docs/reference/resource-inference.md +149 -0
- package/skills/void/docs/reference/structure.md +176 -0
- package/.npmignore +0 -29
- package/.travis.yml +0 -9
- package/favicon.ico +0 -0
- package/index.js +0 -14
- package/lib/Job.js +0 -150
- package/lib/Void.js +0 -99
- package/lib/scan.js +0 -19
- package/test/credentials.js +0 -20
- package/test/job.js +0 -64
- package/test/static/dir1/test6.html +0 -0
- package/test/static/dir2/test7.html +0 -0
- package/test/static/dir2/test8.html +0 -0
- package/test/static/dir2/test9.html +0 -0
- package/test/static/test1.html +0 -0
- package/test/static/test2.html +0 -0
- package/test/static/test3.html +0 -0
- package/test/void.js +0 -31
- /package/{test/static/dir1/test4.html → skills/void/docs/integrations/auth-providers.md} +0 -0
- /package/{test/static/dir1/test5.html → skills/void/docs/integrations/payment-processors.md} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
outline: deep
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# D1 (SQLite)
|
|
6
|
+
|
|
7
|
+
[Cloudflare D1](https://developers.cloudflare.com/d1/) is a serverless SQLite database distributed across Cloudflare's network. Void manages it for you, so there is no setup, no connection string, and no separate local database configuration during development.
|
|
8
|
+
|
|
9
|
+
## When to Use D1
|
|
10
|
+
|
|
11
|
+
D1 is the default database for Void apps and a great choice when you want zero-config database access:
|
|
12
|
+
|
|
13
|
+
- **Prototyping:** start building immediately with no external database to provision
|
|
14
|
+
- **Read-heavy apps:** optimized for read workloads at the edge
|
|
15
|
+
- **Small to medium scale:** a good fit for apps that do not need advanced SQL features such as stored procedures or complex joins
|
|
16
|
+
- **Simplicity:** Void creates, migrates, and manages the D1 instance for you
|
|
17
|
+
|
|
18
|
+
For write-heavy workloads, complex queries, or connecting to existing infrastructure, see [PostgreSQL](./postgresql).
|
|
19
|
+
|
|
20
|
+
## Configuration
|
|
21
|
+
|
|
22
|
+
None. D1 is the default dialect, so you can start by defining your schema and querying.
|
|
23
|
+
|
|
24
|
+
## Migrations & Prototyping
|
|
25
|
+
|
|
26
|
+
Void offers two workflows for applying schema changes.
|
|
27
|
+
|
|
28
|
+
### Prototyping with `push`
|
|
29
|
+
|
|
30
|
+
During development, use `void db push` to apply your schema directly to the local D1 database. It does not create migration files.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
void db push
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This diffs your Drizzle schema against the local database and applies the changes immediately. It's fast and ideal for iterating on your schema before committing to a migration.
|
|
37
|
+
|
|
38
|
+
### Production migrations
|
|
39
|
+
|
|
40
|
+
When you're ready to ship, generate SQL migration files from your schema:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
void db generate
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This creates timestamped SQL files in `db/migrations/` that capture the diff between your schema and the last generated migration.
|
|
47
|
+
|
|
48
|
+
To apply pending migrations locally:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
void db migrate
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Deploy Workflow
|
|
55
|
+
|
|
56
|
+
When you run `void deploy`:
|
|
57
|
+
|
|
58
|
+
1. The app is built
|
|
59
|
+
2. Migration files are collected from `db/migrations/`
|
|
60
|
+
3. If the schema has drifted ahead of the migrations, you're prompted to generate and commit the new migrations
|
|
61
|
+
4. Pending migrations run against the remote D1 database
|
|
62
|
+
5. The new worker goes live
|
|
63
|
+
|
|
64
|
+
Deploys always go through migration files. `push` is only for local development.
|
|
65
|
+
|
|
66
|
+
## Batch Operations
|
|
67
|
+
|
|
68
|
+
D1 supports batching multiple statements into a single round-trip:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { db, eq } from 'void/db';
|
|
72
|
+
import { users, posts } from '@schema';
|
|
73
|
+
|
|
74
|
+
await db.batch([
|
|
75
|
+
db.delete(posts).where(eq(posts.userId, userId)),
|
|
76
|
+
db.delete(users).where(eq(users.id, userId)),
|
|
77
|
+
]);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Alternative Query Layers
|
|
81
|
+
|
|
82
|
+
While Void's Drizzle integration is the recommended approach, you can use any library that accepts a D1 binding. Import `env.DB` from `cloudflare:workers` and pass it to your library:
|
|
83
|
+
|
|
84
|
+
### Kysely
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { Kysely } from 'kysely';
|
|
88
|
+
import { D1Dialect } from 'kysely-d1';
|
|
89
|
+
import { env } from 'cloudflare:workers';
|
|
90
|
+
|
|
91
|
+
const db = new Kysely<Database>({ dialect: new D1Dialect({ database: env.DB }) });
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Raw D1
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { env } from 'cloudflare:workers';
|
|
98
|
+
|
|
99
|
+
const { results } = await env.DB.prepare('SELECT * FROM users WHERE id = ?').bind(userId).all();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Void still handles binding inference and deployment regardless of which query layer you use.
|
|
103
|
+
|
|
104
|
+
::: warning ⚠️ Meta framework limitation
|
|
105
|
+
Some frameworks, like Nuxt and SvelteKit, do not run in workerd during dev and therefore do not support directly importing from `cloudflare:workers`.
|
|
106
|
+
:::
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
outline: deep
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# PostgreSQL
|
|
6
|
+
|
|
7
|
+
Void supports PostgreSQL via [Cloudflare Hyperdrive](https://developers.cloudflare.com/hyperdrive/). You bring the Postgres database, and Void handles connection pooling plus deployment wiring through the same Drizzle-based workflow used for D1.
|
|
8
|
+
|
|
9
|
+
## What is Hyperdrive?
|
|
10
|
+
|
|
11
|
+
Hyperdrive is Cloudflare's connection pooling and caching layer for PostgreSQL. It maintains persistent connections from the edge to your database, dramatically reducing connection latency. Instead of establishing a new TCP + TLS connection on every request, your Worker reuses pooled connections through Hyperdrive.
|
|
12
|
+
|
|
13
|
+
Void manages the Hyperdrive configuration automatically. You only provide the connection string.
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
### 1. Set the database
|
|
18
|
+
|
|
19
|
+
Add to your `void.json`:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"database": "pg"
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 2. Add your connection string
|
|
28
|
+
|
|
29
|
+
For local development, add `DATABASE_URL` to `.env.local`:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
DATABASE_URL=postgres://user:password@host:5432/mydb
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This connects directly to your Postgres database during `void dev`.
|
|
36
|
+
|
|
37
|
+
### 3. Deploy
|
|
38
|
+
|
|
39
|
+
On your first deploy, the CLI will prompt for your connection string:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
Your project uses PostgreSQL. Enter your connection string:
|
|
43
|
+
> postgres://user:password@host:5432/mydb
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Void provisions a Hyperdrive configuration and stores only the config ID. Your connection string is sent directly to Cloudflare's API and is never stored by Void.
|
|
47
|
+
|
|
48
|
+
You can also set the connection string ahead of time with `void db set-url`.
|
|
49
|
+
|
|
50
|
+
## Schema Definition
|
|
51
|
+
|
|
52
|
+
With the `postgresql` dialect, import schema helpers from `void/schema-pg` (re-exports from `drizzle-orm/pg-core`):
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
// db/schema.ts
|
|
56
|
+
import { pgTable, serial, text, timestamp, boolean, doublePrecision } from 'void/schema-pg';
|
|
57
|
+
|
|
58
|
+
export const users = pgTable('users', {
|
|
59
|
+
id: serial('id').primaryKey(),
|
|
60
|
+
name: text('name').notNull(),
|
|
61
|
+
email: text('email').notNull().unique(),
|
|
62
|
+
role: text('role').notNull().default('user'),
|
|
63
|
+
active: boolean('active').notNull().default(true),
|
|
64
|
+
createdAt: timestamp('created_at').notNull().defaultNow(),
|
|
65
|
+
updatedAt: timestamp('updated_at').notNull().defaultNow(),
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`void gen model` generates PostgreSQL-appropriate code when the dialect is set to `postgresql`.
|
|
70
|
+
|
|
71
|
+
## Migrations
|
|
72
|
+
|
|
73
|
+
The migration workflow is the same as D1:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Generate migration files from schema changes
|
|
77
|
+
void db generate
|
|
78
|
+
|
|
79
|
+
# Apply pending migrations locally
|
|
80
|
+
void db migrate
|
|
81
|
+
|
|
82
|
+
# Check migration status
|
|
83
|
+
void db status
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The main difference is that PostgreSQL supports **transactional DDL**. Each migration is wrapped in `BEGIN` and `COMMIT`, so a failure rolls back the whole migration instead of leaving the database half-updated.
|
|
87
|
+
|
|
88
|
+
## Deploy Workflow
|
|
89
|
+
|
|
90
|
+
When you run `void deploy` with a PostgreSQL project:
|
|
91
|
+
|
|
92
|
+
1. The app is built
|
|
93
|
+
2. Migration files are collected from `db/migrations/`
|
|
94
|
+
3. If Hyperdrive hasn't been provisioned yet, you're prompted for the connection string
|
|
95
|
+
4. Pending migrations run inside the deployed worker via Hyperdrive
|
|
96
|
+
5. The new worker goes live
|
|
97
|
+
|
|
98
|
+
## Updating the Connection String
|
|
99
|
+
|
|
100
|
+
To update the connection string for an existing deployment (e.g. migrating to a new database host):
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
void db set-url
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
This prompts for the new connection string and updates the Hyperdrive configuration. The change takes effect on the next deploy.
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
---
|
|
2
|
+
outline: deep
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
<script setup>
|
|
6
|
+
const dbFileItems = [
|
|
7
|
+
{
|
|
8
|
+
name: "db/",
|
|
9
|
+
children: [
|
|
10
|
+
{ name: "schema.ts", description: "Table definitions (source of truth)" },
|
|
11
|
+
{
|
|
12
|
+
name: "schema/",
|
|
13
|
+
description: "Split schema files (optional)",
|
|
14
|
+
children: [
|
|
15
|
+
{ name: "users.ts" },
|
|
16
|
+
{ name: "posts.ts" },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "migrations/",
|
|
21
|
+
description: "Generated SQL migration files",
|
|
22
|
+
children: [
|
|
23
|
+
{ name: "20260410161500_create_users.sql" },
|
|
24
|
+
{ name: "20260410161501_add_posts.sql" },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
{ name: "seed.ts", description: "Programmatic seed script (optional)" },
|
|
28
|
+
{ name: "seed.sql", description: "Raw SQL seed file (optional alternative)" },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
# Database
|
|
35
|
+
|
|
36
|
+
Void provides a first-class [Drizzle ORM](https://orm.drizzle.team) integration. Define your schema in TypeScript, import the pre-wired Drizzle instance from `void/db`, and start querying. You do not need an extra install.
|
|
37
|
+
|
|
38
|
+
<FileTree :items="dbFileItems" default-expanded />
|
|
39
|
+
|
|
40
|
+
## Choosing a Dialect
|
|
41
|
+
|
|
42
|
+
Void supports two database backends. Both use the same Drizzle-based workflow for schema definition, querying, and migrations.
|
|
43
|
+
|
|
44
|
+
`void init` can start you with D1, PostgreSQL, or no database yet. Choosing D1 keeps the default implicit; choosing PostgreSQL writes `"database": "pg"` to `void.json`; choosing no database lets you start with static Pages and adopt data features later.
|
|
45
|
+
|
|
46
|
+
| | [D1 (SQLite)](./database/d1) | [PostgreSQL](./database/postgresql) |
|
|
47
|
+
| ---------- | ---------------------------- | -------------------------------------------- |
|
|
48
|
+
| Config | Default (no config needed) | `"database": "pg"` in `void.json` |
|
|
49
|
+
| Managed by | Void (fully managed) | Bring your own database |
|
|
50
|
+
| Best for | Read-heavy apps, prototyping | Write-heavy, complex queries, existing infra |
|
|
51
|
+
| Connection | Automatic D1 binding | Hyperdrive connection pooling |
|
|
52
|
+
|
|
53
|
+
## Schema Definition
|
|
54
|
+
|
|
55
|
+
Define your tables in `db/schema.ts` using column helpers from `void/schema-d1` or `void/schema-pg`. This file is the source of truth for your database structure:
|
|
56
|
+
|
|
57
|
+
::: code-group
|
|
58
|
+
|
|
59
|
+
```ts [SQLite (D1)]
|
|
60
|
+
// db/schema.ts
|
|
61
|
+
import { sqliteTable, text, integer } from 'void/schema-d1';
|
|
62
|
+
import { sql } from 'void/db';
|
|
63
|
+
|
|
64
|
+
export const users = sqliteTable('users', {
|
|
65
|
+
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
66
|
+
name: text('name').notNull(),
|
|
67
|
+
email: text('email').notNull().unique(),
|
|
68
|
+
role: text('role').notNull().default('user'),
|
|
69
|
+
createdAt: text('created_at')
|
|
70
|
+
.notNull()
|
|
71
|
+
.default(sql`(datetime('now'))`),
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```ts [PostgreSQL]
|
|
76
|
+
// db/schema.ts
|
|
77
|
+
import { pgTable, serial, text, timestamp } from 'void/schema-pg';
|
|
78
|
+
|
|
79
|
+
export const users = pgTable('users', {
|
|
80
|
+
id: serial('id').primaryKey(),
|
|
81
|
+
name: text('name').notNull(),
|
|
82
|
+
email: text('email').notNull().unique(),
|
|
83
|
+
role: text('role').notNull().default('user'),
|
|
84
|
+
createdAt: timestamp('created_at').notNull().defaultNow(),
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
:::
|
|
89
|
+
|
|
90
|
+
Everything ships with `void`, so there is nothing extra to install. You also do not have to write this by hand. Use `void gen model` or let your coding agent generate it.
|
|
91
|
+
|
|
92
|
+
You can also split your schema across multiple files under `db/schema/` and re-export from a barrel file:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
// db/schema/users.ts
|
|
96
|
+
export const users = ...;
|
|
97
|
+
|
|
98
|
+
// db/schema/posts.ts
|
|
99
|
+
export const posts = ...;
|
|
100
|
+
|
|
101
|
+
// db/schema.ts (barrel)
|
|
102
|
+
export * from "./schema/users";
|
|
103
|
+
export * from "./schema/posts";
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Querying
|
|
107
|
+
|
|
108
|
+
Void re-exports all common [Drizzle query operators](https://orm.drizzle.team/docs/select) from `void/db` so you don't need to install `drizzle-orm` separately. Import `db` from `void/db` and your tables from `@schema`:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { db } from 'void/db';
|
|
112
|
+
import { users } from '@schema';
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
::: info What is `@schema`?
|
|
116
|
+
`@schema` is a Vite path alias that the Void plugin configures automatically. It points to your `db/schema.ts` file, or `db/schema/` if you split tables across files. You can just use it to import table definitions.
|
|
117
|
+
:::
|
|
118
|
+
|
|
119
|
+
### List rows
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const allUsers = await db.select().from(users);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Filter with `where`
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { db, eq, and, or } from 'void/db';
|
|
129
|
+
import { users } from '@schema';
|
|
130
|
+
|
|
131
|
+
// Single condition
|
|
132
|
+
const user = await db.select().from(users).where(eq(users.id, 1));
|
|
133
|
+
|
|
134
|
+
// Multiple conditions
|
|
135
|
+
const admins = await db
|
|
136
|
+
.select()
|
|
137
|
+
.from(users)
|
|
138
|
+
.where(and(eq(users.role, 'admin'), eq(users.name, 'Alice')));
|
|
139
|
+
|
|
140
|
+
// OR conditions
|
|
141
|
+
const result = await db
|
|
142
|
+
.select()
|
|
143
|
+
.from(users)
|
|
144
|
+
.where(or(eq(users.role, 'admin'), eq(users.role, 'editor')));
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Insert
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
// Single row
|
|
151
|
+
await db.insert(users).values({
|
|
152
|
+
name: 'Alice',
|
|
153
|
+
email: 'alice@example.com',
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Insert and return the created row
|
|
157
|
+
const [created] = await db
|
|
158
|
+
.insert(users)
|
|
159
|
+
.values({ name: 'Bob', email: 'bob@example.com' })
|
|
160
|
+
.returning();
|
|
161
|
+
|
|
162
|
+
// Multiple rows
|
|
163
|
+
await db.insert(users).values([
|
|
164
|
+
{ name: 'Alice', email: 'alice@example.com' },
|
|
165
|
+
{ name: 'Bob', email: 'bob@example.com' },
|
|
166
|
+
]);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Update
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
await db.update(users).set({ role: 'admin' }).where(eq(users.id, 1));
|
|
173
|
+
|
|
174
|
+
// Update and return the modified row
|
|
175
|
+
const [updated] = await db.update(users).set({ role: 'admin' }).where(eq(users.id, 1)).returning();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Delete
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
await db.delete(users).where(eq(users.id, 1));
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Column selection
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
const names = await db.select({ name: users.name, email: users.email }).from(users);
|
|
188
|
+
// names: { name: string; email: string }[]
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Ordering and pagination
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { db, desc } from 'void/db';
|
|
195
|
+
import { users } from '@schema';
|
|
196
|
+
|
|
197
|
+
const page = await db.select().from(users).orderBy(desc(users.createdAt)).limit(10).offset(20);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Joins
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import { db, eq } from 'void/db';
|
|
204
|
+
import { users, posts } from '@schema';
|
|
205
|
+
|
|
206
|
+
const results = await db
|
|
207
|
+
.select({
|
|
208
|
+
id: posts.id,
|
|
209
|
+
title: posts.title,
|
|
210
|
+
author: users.name,
|
|
211
|
+
})
|
|
212
|
+
.from(posts)
|
|
213
|
+
.innerJoin(users, eq(posts.userId, users.id));
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Relational queries
|
|
217
|
+
|
|
218
|
+
If your schema defines [relations](https://orm.drizzle.team/docs/relations), you can use Drizzle's relational query API:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const usersWithPosts = await db.query.users.findMany({
|
|
222
|
+
with: { posts: true },
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The user schema is automatically loaded into the `db` instance via a Vite plugin, so relational queries work out of the box.
|
|
227
|
+
|
|
228
|
+
::: warning ⚠️ Nuxt and Analog limitations
|
|
229
|
+
Nuxt and Analog use Nitro, which bundles server routes outside of Vite's plugin pipeline. The schema cannot be injected into the `db` instance, so `db.query.*` relational queries are not available in Nuxt and Analog. Use the standard query builder API (`db.select().from(table)`) instead.
|
|
230
|
+
:::
|
|
231
|
+
|
|
232
|
+
## Seeding
|
|
233
|
+
|
|
234
|
+
Use `void db seed` to reset your local database, re-apply migrations, and then run a seed file.
|
|
235
|
+
|
|
236
|
+
Void resolves default seed files in this order:
|
|
237
|
+
|
|
238
|
+
1. `db/seed.ts`
|
|
239
|
+
2. `db/seed.mts`
|
|
240
|
+
3. `db/seed.js`
|
|
241
|
+
4. `db/seed.mjs`
|
|
242
|
+
5. `db/seed.sql`
|
|
243
|
+
|
|
244
|
+
If more than one default seed file exists, pass `--file <path>` explicitly.
|
|
245
|
+
|
|
246
|
+
### Programmatic seeding
|
|
247
|
+
|
|
248
|
+
`db/seed.ts` is the first-class path for generated or randomized data. Seed modules can export either a default function or a named `seed` function.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
// db/seed.ts
|
|
252
|
+
import { defineSeed } from 'void/seed';
|
|
253
|
+
|
|
254
|
+
export default defineSeed<typeof import('./schema')>(async ({ db, schema }) => {
|
|
255
|
+
const rows = Array.from({ length: 100 }, (_, i) => ({
|
|
256
|
+
text: `Seed message ${i + 1}`,
|
|
257
|
+
}));
|
|
258
|
+
|
|
259
|
+
await db.insert(schema.messages).values(rows);
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The seed context includes:
|
|
264
|
+
|
|
265
|
+
- `dialect`: `"sqlite"` or `"postgresql"`
|
|
266
|
+
- `db`: a Drizzle instance for the local database
|
|
267
|
+
- `schema`: the exports from your `db/schema.ts` or `db/schema/` modules
|
|
268
|
+
|
|
269
|
+
### SQL seeding
|
|
270
|
+
|
|
271
|
+
If you prefer raw SQL, keep using `db/seed.sql`:
|
|
272
|
+
|
|
273
|
+
```sql
|
|
274
|
+
INSERT INTO messages (text) VALUES ('Hello from SQL');
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Schema-Derived Validators
|
|
278
|
+
|
|
279
|
+
Instead of writing validator schemas by hand, you can derive them directly from your Drizzle tables using Void's bundled adapter entrypoints: [`void/drizzle-zod`](../reference/api.md#subpath-exports), [`void/drizzle-valibot`](../reference/api.md#subpath-exports), and [`void/drizzle-arktype`](../reference/api.md#subpath-exports). These resolve through the same package boundary as `void/schema-*`, so the generated validators stay type-compatible with your tables automatically.
|
|
280
|
+
|
|
281
|
+
::: code-group
|
|
282
|
+
|
|
283
|
+
```ts [Zod]
|
|
284
|
+
// db/schema.ts
|
|
285
|
+
import { sqliteTable, text, integer } from 'void/schema-d1';
|
|
286
|
+
import { sql } from 'void/db';
|
|
287
|
+
import { createInsertSchema } from 'void/drizzle-zod';
|
|
288
|
+
|
|
289
|
+
export const users = sqliteTable('users', {
|
|
290
|
+
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
291
|
+
name: text('name').notNull(),
|
|
292
|
+
email: text('email').notNull(),
|
|
293
|
+
createdAt: text('created_at')
|
|
294
|
+
.notNull()
|
|
295
|
+
.default(sql`(datetime('now'))`),
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
export const insertUserSchema = createInsertSchema(users, {
|
|
299
|
+
name: (schema) => schema.min(1),
|
|
300
|
+
email: (schema) => schema.email(),
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
```ts [Valibot]
|
|
305
|
+
// db/schema.ts
|
|
306
|
+
import { sqliteTable, text, integer } from 'void/schema-d1';
|
|
307
|
+
import { sql } from 'void/db';
|
|
308
|
+
import { createInsertSchema } from 'void/drizzle-valibot';
|
|
309
|
+
import { pipe, minLength, email } from 'valibot';
|
|
310
|
+
|
|
311
|
+
export const users = sqliteTable('users', {
|
|
312
|
+
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
313
|
+
name: text('name').notNull(),
|
|
314
|
+
email: text('email').notNull(),
|
|
315
|
+
createdAt: text('created_at')
|
|
316
|
+
.notNull()
|
|
317
|
+
.default(sql`(datetime('now'))`),
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
export const insertUserSchema = createInsertSchema(users, {
|
|
321
|
+
name: (schema) => pipe(schema, minLength(1)),
|
|
322
|
+
email: (schema) => pipe(schema, email()),
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
```ts [ArkType]
|
|
327
|
+
// db/schema.ts
|
|
328
|
+
import { sqliteTable, text, integer } from 'void/schema-d1';
|
|
329
|
+
import { sql } from 'void/db';
|
|
330
|
+
import { createInsertSchema } from 'void/drizzle-arktype';
|
|
331
|
+
import { type } from 'arktype';
|
|
332
|
+
|
|
333
|
+
export const users = sqliteTable('users', {
|
|
334
|
+
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
335
|
+
name: text('name').notNull(),
|
|
336
|
+
email: text('email').notNull(),
|
|
337
|
+
createdAt: text('created_at')
|
|
338
|
+
.notNull()
|
|
339
|
+
.default(sql`(datetime('now'))`),
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
export const insertUserSchema = createInsertSchema(users, {
|
|
343
|
+
name: type('string > 0'),
|
|
344
|
+
email: type('string.email'),
|
|
345
|
+
});
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
:::
|
|
349
|
+
|
|
350
|
+
`createInsertSchema` generates a validator that matches `$inferInsert`. Columns with defaults or auto-increments become optional, while `NOT NULL` columns stay required. The optional second argument lets you refine individual columns, either with a callback that receives the generated schema or by passing a type directly to override a field.
|
|
351
|
+
|
|
352
|
+
Use the derived schema in your route handlers with [`withValidator()`](./server-routing.md#validation):
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
// routes/api/users/index.ts
|
|
356
|
+
import { defineHandler } from 'void';
|
|
357
|
+
import { db } from 'void/db';
|
|
358
|
+
import { users, insertUserSchema } from '@schema';
|
|
359
|
+
|
|
360
|
+
export const POST = defineHandler.withValidator({
|
|
361
|
+
body: insertUserSchema,
|
|
362
|
+
})(async (c, { body }) => {
|
|
363
|
+
const [created] = await db.insert(users).values(body).returning();
|
|
364
|
+
return created;
|
|
365
|
+
});
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Three functions are available:
|
|
369
|
+
|
|
370
|
+
| Function | Purpose |
|
|
371
|
+
| -------------------- | ----------------------------------------------------------------------------- |
|
|
372
|
+
| `createInsertSchema` | Validates insert data, excluding auto-generated columns and applying defaults |
|
|
373
|
+
| `createSelectSchema` | Matches the shape of selected rows |
|
|
374
|
+
| `createUpdateSchema` | Like insert but all fields are optional (partial update) |
|
|
375
|
+
|
|
376
|
+
Void already bundles the Drizzle adapters. Install the validator library itself if you use its direct APIs in your schema file:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
npm install zod
|
|
380
|
+
# or
|
|
381
|
+
npm install valibot
|
|
382
|
+
# or
|
|
383
|
+
npm install arktype
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
## CLI Commands
|
|
387
|
+
|
|
388
|
+
| Command | Purpose |
|
|
389
|
+
| ------------------ | ------------------------------------------------------------- |
|
|
390
|
+
| `void db push` | Apply schema directly to local database (no migration files) |
|
|
391
|
+
| `void db generate` | Generate SQL migration files from schema changes |
|
|
392
|
+
| `void db migrate` | Apply pending migrations locally |
|
|
393
|
+
| `void db status` | Show schema drift and pending migrations |
|
|
394
|
+
| `void db reset` | Drop the local DB and re-apply all migrations |
|
|
395
|
+
| `void db seed` | Reset + run seed file (`--file <path>`) |
|
|
396
|
+
| `void db execute` | Run ad-hoc SQL against local DB (`--file <path>`) |
|
|
397
|
+
| `void db studio` | Open Drizzle Studio for the local database |
|
|
398
|
+
| `void db export` | Dump local DB as SQL (`--output`, `--no-data`, `--no-schema`) |
|
|
399
|
+
| `void db set-url` | Update the PostgreSQL connection string for deployment |
|
|
400
|
+
|
|
401
|
+
See the [CLI reference](../reference/cli.md#database) for details.
|
|
402
|
+
|
|
403
|
+
## Scaffolding
|
|
404
|
+
|
|
405
|
+
The `void gen model` command scaffolds a Drizzle table definition and updates your barrel export. It generates dialect-appropriate code: `sqliteTable` for D1 and `pgTable` for PostgreSQL.
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
void gen model post title:string body:text published:boolean
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
This creates:
|
|
412
|
+
|
|
413
|
+
1. `db/schema/post.ts`: a Drizzle table definition with `id`, `createdAt`, `updatedAt`, and your columns
|
|
414
|
+
2. Updates `db/schema.ts` with `export * from "./schema/post"`
|
|
415
|
+
3. `routes/api/posts/index.ts`: `GET` for list and `POST` for insert with validation
|
|
416
|
+
4. `routes/api/posts/[id].ts`: `GET` by id with `404` handling
|
|
417
|
+
|
|
418
|
+
See the [CLI reference](../reference/cli.md#code-generation) for the full list of generators.
|