Stathis
Stathis
DTDrizzle Team
Created by titongo on 11/9/2023 in #help
need help abstracting a function
@Aaron sorry for bumping you again, how to do you type function parameters? eg. I want to pass the result to a function:
await doSomethingWithTheResult({
post: result[0],
});
await doSomethingWithTheResult({
post: result[0],
});
async function doSomethingWithTheResult(post: <HOW_TO_TYPE_THIS>) {}
async function doSomethingWithTheResult(post: <HOW_TO_TYPE_THIS>) {}
No matter what I tried I could not type the with, in this case post.post_images
12 replies
DTDrizzle Team
Created by Stathis on 3/1/2024 in #help
Seems like the schema generic is missing - did you forget to add it to your DB type?
Nice catch, totally missed it 🤦‍♂️
6 replies
DTDrizzle Team
Created by titongo on 11/9/2023 in #help
need help abstracting a function
@Aaron did you managed to type the response incluiding the relations? Really struggling with this now...
12 replies
DTDrizzle Team
Created by Stathis on 3/1/2024 in #help
Seems like the schema generic is missing - did you forget to add it to your DB type?
found the issue:
export const db =
process.env.NAME === "Offline"
? db_dev
: // @ts-ignore
drizzle(rdsClient, {
database: process.env["DATABASE"]!,
secretArn: process.env["SECRET_ARN"]!,
resourceArn: process.env["RESOURCE_ARN"]!
});
export const db =
process.env.NAME === "Offline"
? db_dev
: // @ts-ignore
drizzle(rdsClient, {
database: process.env["DATABASE"]!,
secretArn: process.env["SECRET_ARN"]!,
resourceArn: process.env["RESOURCE_ARN"]!
});
it seems it cannot infer types due to the ternary operator. Is there a way around it?
6 replies
DTDrizzle Team
Created by Stathis on 3/1/2024 in #help
Seems like the schema generic is missing - did you forget to add it to your DB type?
throws:
TS2339: Property post does not exist on type
DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> | { post: RelationalQueryBuilder<ExtractTablesWithRelations<{ post: PgTableWithColumns<{ name: "post"; schema: undefined; columns: { ...; }; dialect: "pg"; }>; postRelations: Relations<...>; post_image: PgTableWi...
Property 'post' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.
TS2339: Property post does not exist on type
DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> | { post: RelationalQueryBuilder<ExtractTablesWithRelations<{ post: PgTableWithColumns<{ name: "post"; schema: undefined; columns: { ...; }; dialect: "pg"; }>; postRelations: Relations<...>; post_image: PgTableWi...
Property 'post' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.
6 replies
DTDrizzle Team
Created by Stathis on 3/1/2024 in #help
Seems like the schema generic is missing - did you forget to add it to your DB type?
schemas:
export const post = pgTable("post", {
id: uuid("id")
.default(sql`gen_random_uuid()`)
.primaryKey(),
admin_deleted_at: timestamp("admin_deleted_at", { withTimezone: true }),
author_id: text("author_id").notNull(),
category_id: uuid("category_id"),
category_name: text("category_name"),
content: text("content").notNull(),
created_at: timestamp("created_at", { withTimezone: true }).defaultNow(),
delete_reason: text("delete_reason"),
deleted_at: timestamp("deleted_at", { withTimezone: true }).defaultNow(),
deleted_by_admin: boolean("deleted_by_admin"),
deleted_by_id: text("deleted_by_id"),
deleted_by_user: boolean("deleted_by_user"),
disable_interactions: boolean("disable_interactions").default(false),
edited_at: timestamp("edited_at", { withTimezone: true }).defaultNow(),
firebase_id: text("firebase_id"),
flair: uuid("flair"),
flair_id: uuid("flair_id"),
hashtag: text("hashtag"),
hidden_from_profile: boolean("hidden_from_profile").default(false),
is_pinned: boolean("is_pinned").default(false),
language: text("language").default("en"),
locked: boolean("locked").default(false),
over18: boolean("over18").default(false),
// rank: bigint("rank", { mode: "bigint" }),
reports_ignored: boolean("reports_ignored").default(false),
//score: bigint("score", { mode: "bigint" }),
title: text("title"),
top_order: timestamp("top_order", { withTimezone: true }),
trigger_warning: boolean("trigger_warning").default(false),
type: text("type").notNull(),
updated_at: timestamp("created_at", { withTimezone: true }).defaultNow(),
video: jsonb("video"),
violated: boolean("violated").default(false)
});
export const post = pgTable("post", {
id: uuid("id")
.default(sql`gen_random_uuid()`)
.primaryKey(),
admin_deleted_at: timestamp("admin_deleted_at", { withTimezone: true }),
author_id: text("author_id").notNull(),
category_id: uuid("category_id"),
category_name: text("category_name"),
content: text("content").notNull(),
created_at: timestamp("created_at", { withTimezone: true }).defaultNow(),
delete_reason: text("delete_reason"),
deleted_at: timestamp("deleted_at", { withTimezone: true }).defaultNow(),
deleted_by_admin: boolean("deleted_by_admin"),
deleted_by_id: text("deleted_by_id"),
deleted_by_user: boolean("deleted_by_user"),
disable_interactions: boolean("disable_interactions").default(false),
edited_at: timestamp("edited_at", { withTimezone: true }).defaultNow(),
firebase_id: text("firebase_id"),
flair: uuid("flair"),
flair_id: uuid("flair_id"),
hashtag: text("hashtag"),
hidden_from_profile: boolean("hidden_from_profile").default(false),
is_pinned: boolean("is_pinned").default(false),
language: text("language").default("en"),
locked: boolean("locked").default(false),
over18: boolean("over18").default(false),
// rank: bigint("rank", { mode: "bigint" }),
reports_ignored: boolean("reports_ignored").default(false),
//score: bigint("score", { mode: "bigint" }),
title: text("title"),
top_order: timestamp("top_order", { withTimezone: true }),
trigger_warning: boolean("trigger_warning").default(false),
type: text("type").notNull(),
updated_at: timestamp("created_at", { withTimezone: true }).defaultNow(),
video: jsonb("video"),
violated: boolean("violated").default(false)
});
When trying to:
const result = await db.query.post.findMany({
with: {
post_image: true
},
where: eq(post.id, postId)
});
const result = await db.query.post.findMany({
with: {
post_image: true
},
where: eq(post.id, postId)
});
6 replies