feat: move perf,logs and user into sqlite

This commit is contained in:
2025-01-05 18:03:59 +01:00
parent 1937ef55bb
commit bf7d88a588
25 changed files with 524 additions and 145 deletions

45
lib/sqlite/schema.ts Normal file
View File

@ -0,0 +1,45 @@
import { int, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { sql } from "drizzle-orm/sql";
export const userTable = sqliteTable("user", {
id: text()
.primaryKey(),
createdAt: integer("created_at", { mode: "timestamp" })
.default(sql`(current_timestamp)`)
.notNull(),
email: text()
.notNull(),
name: text()
.notNull(),
});
export const sessionTable = sqliteTable("session", {
id: text("id")
.primaryKey(),
createdAt: integer("created_at", { mode: "timestamp_ms" }).default(
sql`(current_timestamp)`,
),
expiresAt: integer("expires_at", { mode: "timestamp" })
.notNull(),
userId: text("user_id")
.notNull(),
});
export const performanceTable = sqliteTable("performance", {
path: text().notNull(),
search: text(),
time: int().notNull(),
createdAt: integer("created_at", {
mode: "timestamp_ms",
}).default(sql`(STRFTIME('%s', 'now') * 1000)`),
});
export const imageTable = sqliteTable("image", {
createdAt: integer("created_at", { mode: "timestamp" }).default(
sql`(current_timestamp)`,
),
path: text().notNull(),
average: text().notNull(),
blurhash: text().notNull(),
mime: text().notNull(),
});

14
lib/sqlite/sqlite.ts Normal file
View File

@ -0,0 +1,14 @@
import { drizzle } from "drizzle-orm/libsql/node";
import { DATA_DIR } from "@lib/env.ts";
import path from "node:path";
// const DB_FILE = "file://" + path.resolve(DATA_DIR, "db.sqlite");
const DB_FILE = "file:data-dev/db.sqlite";
// You can specify any property from the libsql connection options
export const db = drizzle({
logger: true,
connection: {
url: DB_FILE,
},
});