feat: setup drizzle
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import Image from "next/image";
|
||||
|
||||
export default function Home() {
|
||||
import { db, users } from "@/db";
|
||||
|
||||
async function getUsers() {
|
||||
return await db.select().from(users);
|
||||
}
|
||||
|
||||
export default async function Home() {
|
||||
const users = await getUsers();
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||
@@ -50,6 +57,7 @@ export default function Home() {
|
||||
/>
|
||||
Deploy Now
|
||||
</a>
|
||||
<pre>{JSON.stringify(users, null, 2)}</pre>
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
|
||||
11
src/db/index.ts
Normal file
11
src/db/index.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { createClient } from "@libsql/client";
|
||||
import { drizzle } from "drizzle-orm/libsql";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const client = createClient({
|
||||
url: "file:sqlite.db",
|
||||
});
|
||||
|
||||
export const db = drizzle(client, { schema });
|
||||
|
||||
export * from "./schema";
|
||||
22
src/db/schema.ts
Normal file
22
src/db/schema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const users = sqliteTable("users", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
email: text("email").notNull().unique(),
|
||||
createdAt: integer("created_at", { mode: "timestamp" })
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date()),
|
||||
});
|
||||
|
||||
export const posts = sqliteTable("posts", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
title: text("title").notNull(),
|
||||
content: text("content"),
|
||||
authorId: integer("author_id")
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
createdAt: integer("created_at", { mode: "timestamp" })
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date()),
|
||||
});
|
||||
Reference in New Issue
Block a user