feat: completely remove redis
This commit is contained in:
81
lib/db/schema.ts
Normal file
81
lib/db/schema.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import {
|
||||
blob,
|
||||
index,
|
||||
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)`,
|
||||
),
|
||||
url: text().notNull(),
|
||||
average: text().notNull(),
|
||||
blurhash: text().notNull(),
|
||||
mime: text().notNull(),
|
||||
});
|
||||
|
||||
export const documentTable = sqliteTable("document", {
|
||||
name: text().notNull().primaryKey(),
|
||||
lastModified: integer("last_modified").notNull(),
|
||||
content: text(),
|
||||
contentType: text("content_type").notNull(),
|
||||
size: integer().notNull(),
|
||||
perm: text().notNull(),
|
||||
}, (table) => {
|
||||
return [
|
||||
index("name_idx").on(table.name),
|
||||
];
|
||||
});
|
||||
|
||||
export const cacheTable = sqliteTable("cache", {
|
||||
scope: text().notNull(),
|
||||
key: text().notNull().primaryKey(),
|
||||
json: text({ mode: "json" }),
|
||||
binary: blob(),
|
||||
createdAt: integer("created_at", { mode: "timestamp" }).default(
|
||||
sql`(current_timestamp)`,
|
||||
),
|
||||
expiresAt: integer("expires_at", { mode: "timestamp" }),
|
||||
}, (table) => {
|
||||
return [
|
||||
index("key_idx").on(table.key),
|
||||
index("scope_idx").on(table.scope),
|
||||
];
|
||||
});
|
12
lib/db/sqlite.ts
Normal file
12
lib/db/sqlite.ts
Normal file
@ -0,0 +1,12 @@
|
||||
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");
|
||||
|
||||
// You can specify any property from the libsql connection options
|
||||
export const db = drizzle({
|
||||
connection: {
|
||||
url: DB_FILE,
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user