Database
Drizzle ORM & useDB
Learn how to query data Drizzle ORM
The useDB() composable is provided to access the database and perform CRUD operations. It's auto-imported across the project, so you can use it in any file.
Usage
server/database/queries/feedback.ts
import { eq, desc } from "drizzle-orm";
export const getFeedback = async () => {
const feedback = await useDB().query.feedback.findMany({
with: {
user: {
columns: {
hashedPassword: false,
},
},
},
orderBy: [desc(tables.feedback.createdAt)],
});
return feedback;
};
Supersaas database actions
We are following the repository pattern for database actions. This means that each related action has its own file in the server/database/queries
directory.
Available actions
File | Description | Location |
---|---|---|
admin.ts | Everything related to super admin | server/database/queries/auth.ts |
auth.ts | All auth related actions | server/database/queries/auth.ts |
customers.ts | Stripe customers | server/database/queries/customers.ts |
passkeys.ts | Credentials and webauthnchallenges | server/database/queries/passkeys.ts |
posts.ts | This is for a small demo in supersaas | server/database/queries/posts.ts |
stripe.ts | Stripe products and prices | server/database/queries/stripe.ts |
subscriptions.ts | Stripe subscriptions | server/database/queries/subscriptions.ts |
teams.ts | Teams and team members | server/database/queries/teams.ts |
users.ts | Users | server/database/queries/users.ts |
These query files have their own respective query actions.