omar
omar
DTDrizzle Team
Created by omar on 1/29/2024 in #help
Is this a problem with Drizzle or Bun?
I'm having this issue. I hope I can fix it without having to download Node!! Any help is appreciated. https://github.com/oven-sh/bun/issues/7343
5 replies
DTDrizzle Team
Created by omar on 1/15/2024 in #help
Can I use Drizzle in Nextjs client components?
I create this file.
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

const connectionString = process.env.DATABASE_URL_POOL as string;

// Disable prefetch as it is not supported for "Transaction" pool mode
const client = postgres(connectionString, { prepare: false });
export const db = drizzle(client);
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

const connectionString = process.env.DATABASE_URL_POOL as string;

// Disable prefetch as it is not supported for "Transaction" pool mode
const client = postgres(connectionString, { prepare: false });
export const db = drizzle(client);
Can I use it in a client component or should I use it in a server action instead and then use the server action inside a client component?
1 replies
DTDrizzle Team
Created by omar on 1/13/2024 in #help
How to create a variable with the same name as the table name?
I have my schema defined like this.
schema.ts
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
id: serial("id").primaryKey(),
fullName: text("full_name"),
phone: varchar("phone", { length: 256 }),
});

export type User = typeof users.$inferSelect;
schema.ts
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
id: serial("id").primaryKey(),
fullName: text("full_name"),
phone: varchar("phone", { length: 256 }),
});

export type User = typeof users.$inferSelect;
And then I have this file, where I'm trying to query the users.
page.tsx
import db from "@/db";
import { users, User } from "@/db/schema";

export default async function Home() {
const usrs: Array<User> = await db.select().from(users);

console.log("hello");
console.log("users: ", users);

return (
<div>
{usrs.map((usr) => (
<p key={usr.id}>{usr.fullName}</p>
))}
</div>
);
}
page.tsx
import db from "@/db";
import { users, User } from "@/db/schema";

export default async function Home() {
const usrs: Array<User> = await db.select().from(users);

console.log("hello");
console.log("users: ", users);

return (
<div>
{usrs.map((usr) => (
<p key={usr.id}>{usr.fullName}</p>
))}
</div>
);
}
Is there anyway I can reuse the name of the table? For example, const users? Also, I'm new to Postgres and JS ORMs in general, coming from Entity Framework, is there a way to define the model/schema in singular terms and then the ORM rename the table to a plural form? I mean, my schema would be User and then in the database, it will be Users. Thanks!
12 replies