refactor(database): 🎨 Refactor note handling into its own class instead of separate functions

This commit is contained in:
Jesse Wierzbinski 2024-04-16 18:09:21 -10:00
parent 2998cb4deb
commit 9081036c6d
No known key found for this signature in database
36 changed files with 1194 additions and 1215 deletions

View file

@ -289,7 +289,15 @@ export const user = pgTable(
email: text("email"),
note: text("note").default("").notNull(),
isAdmin: boolean("is_admin").default(false).notNull(),
endpoints: jsonb("endpoints"),
endpoints: jsonb("endpoints").$type<Partial<{
dislikes: string;
featured: string;
likes: string;
followers: string;
following: string;
inbox: string;
outbox: string;
}> | null>(),
source: jsonb("source").notNull(),
avatar: text("avatar").notNull(),
header: text("header").notNull(),

39
drizzle/types.ts Normal file
View file

@ -0,0 +1,39 @@
import type {
BuildQueryResult,
DBQueryConfig,
ExtractTablesWithRelations,
} from "drizzle-orm";
import type * as schema from "./schema";
type Schema = typeof schema;
type TablesWithRelations = ExtractTablesWithRelations<Schema>;
export type IncludeRelation<TableName extends keyof TablesWithRelations> =
DBQueryConfig<
"one" | "many",
boolean,
TablesWithRelations,
TablesWithRelations[TableName]
>["with"];
export type IncludeColumns<TableName extends keyof TablesWithRelations> =
DBQueryConfig<
"one" | "many",
boolean,
TablesWithRelations,
TablesWithRelations[TableName]
>["columns"];
export type InferQueryModel<
TableName extends keyof TablesWithRelations,
Columns extends IncludeColumns<TableName> | undefined = undefined,
With extends IncludeRelation<TableName> | undefined = undefined,
> = BuildQueryResult<
TablesWithRelations,
TablesWithRelations[TableName],
{
columns: Columns;
with: With;
}
>;