ORM
ShipNowKit uses the latest version of Prisma (v6) as its ORM.
Why Prisma?
Prisma is an open-source ORM framework that supports multiple databases, including PostgreSQL, MySQL, SQLite, SQL Server, and MongoDB. For a complete list of supported databases, see here.
Prisma provides unified API interfaces and consistent query syntax across these databases, allowing seamless switching between different database types.
For a quick start with Prisma, refer to the official Prisma Getting Started Guide
Database Driver
ShipNowKit uses PostgreSQL as the default database. To switch to a different database, we provide convenient commands. For example, to use MySQL:
npm run db:use:mysql
npm run db:migrate
Database Schema Management
Schema Location
The Prisma schema file is located at db/prisma/schema.prisma
. This file defines all database tables and their relationships.
Pre-configured Tables
The project includes pre-configured tables for authentication and payment systems:
-
Authentication Tables
users
: Core user informationaccounts
: OAuth provider connectionssessions
: User session managementverificationtokens
: Email verification
-
Payment System Tables
customers
: Payment platform customer recordssubscriptions
: Subscription managementone_time_payments
: One-Time payment recordsprices
: Product pricing info
Modifying Database Schema
To modify the database schema, follow these steps:
- Edit the
schema.prisma
file - Create DB-compatible Prisma Client
npm run db:generate
- [relational databases required] Generate migration files and apply to the database:
npm run db:migrate
Database Operations
Querying Data
import { prisma } from "@/db/client"
// Find a single record
const user = await prisma.user.findUnique({
where: { id: userId }
});
// Find multiple records with relations
const users = await prisma.user.findMany({
where: {email: query_email}
});
Writing Data
import { prisma } from "@/db/client"
// Create a record
await prisma.user.create({
data: {
name: 'Alice',
email: '[email protected]'
}
});
// Update a record
await prisma.user.update({
where: { id: userId },
data: { name: 'New Name' }
});
For more detailed information about Prisma features and best practices, refer to the official Prisma documentation.