SQLite

Cloudflare D1 is a serverless SQL database that runs on SQLite.

NuxtHub Database uses Cloudflare D1, a managed, serverless database built on SQLite to store and retrieve relational data.

The official documentation includes a comprehensive overview of the database features and capabilities.

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 the users 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
The generated code is not production-ready and is more like a starting point. You should carefully review and modify the generated code to fit your needs.