SQLite
NuxtHub Database uses Cloudflare D1, a managed, serverless database built on SQLite to store and retrieve relational data.
Drizzle ORM
Instead of using hubDatabase()
to make interact with your database, this starter kit uses Drizzle ORM to improve the developer experience by providing a type-safe API, migrations, and more.
Nuxt Layer
The starter kit includes a Nuxt layer that provides a simple and consistent API for interacting with the database. This module is located in the layers/db
directory and is responsible for managing the database connection, executing queries, and handling errors.
The layer contains the following server files:
db.ts
: This file contains the database connection and configuration.schema.ts
: This file contains the database schema and models.useXXXDb.ts
: Each database table has a corresponding file that contains the CRUD operations for that table. For example,useUserDb.ts
contains the CRUD operations for theusers
table.
Code Generation
I provide a simple code generation script that generates the database schema and models based on the database tables. This script is located at scripts/generateApi.js
and can be run using the following command:
pnpm generate:api