Seems like the schema generic is missing - did you forget to add it to your DB type?

Hi, I cannot get it to work no matter what I tried. Here's the db/index:
import { RDSDataClient } from "@aws-sdk/client-rds-data";
import { fromIni } from "@aws-sdk/credential-providers";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

import * as schema from "./schemas";

const queryClient = postgres(
"postgres://postgres:postgrespassword@localhost:5433/postgres"
);

const db_dev = drizzle(queryClient, {
logger: true,
schema: { ...schema }
});

const rdsClient = new RDSDataClient({
credentials: fromIni({ profile: process.env["PROFILE"] }),
region: "us-east-1"
});

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"]!
});
import { RDSDataClient } from "@aws-sdk/client-rds-data";
import { fromIni } from "@aws-sdk/credential-providers";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

import * as schema from "./schemas";

const queryClient = postgres(
"postgres://postgres:postgrespassword@localhost:5433/postgres"
);

const db_dev = drizzle(queryClient, {
logger: true,
schema: { ...schema }
});

const rdsClient = new RDSDataClient({
credentials: fromIni({ profile: process.env["PROFILE"] }),
region: "us-east-1"
});

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"]!
});
3 Replies
Stathis
StathisOP9mo ago
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)
});
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?">'.
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?
Mykhailo
Mykhailo9mo ago
Hi, @Stathis. As I see, you don't pass schema parameter with rds client.
No description
Stathis
StathisOP9mo ago
Nice catch, totally missed it 🤦‍♂️
Want results from more Discord servers?
Add your server