pedro77
pedro77
Explore posts from servers
DTDrizzle Team
Created by pedro77 on 8/26/2024 in #help
Prisma MySql Integration returns wrong keys in queries
const counted = await tx
.select({
count: count(),
})
.from(TableX)
.where(
eq(TableX.id, id),
)
const counted = await tx
.select({
count: count(),
})
.from(TableX)
.where(
eq(TableX.id, id),
)
Output
[{ 'count(*)': 1n }]
[{ 'count(*)': 1n }]
Keys get worse when using complex sql`` operator calls This makes unusable drizzle for me, I don't know how to get rid of the too many connnections problem when gradually adopting drizzle, I need some advise.🙏 Github issue here: https://github.com/drizzle-team/drizzle-orm/issues/2848
1 replies
DTDrizzle Team
Created by pedro77 on 7/23/2024 in #help
Is it possible to have a common transaction between prisma and drizzle?
I want to use drizzle and prisma within the same transaction.
1 replies
DTDrizzle Team
Created by pedro77 on 5/24/2024 in #help
sql.raw() does not get columns from Table object
sql.raw(`date_format(${MyTable.mycolumn}, "%d-%m-%Y") like "%${search}%"`) // This errors

sql.raw(`date_format(${MyTable.mycolumn.name}, "%d-%m-%Y") like "%${search}%"`) // This Works!
sql.raw(`date_format(${MyTable.mycolumn}, "%d-%m-%Y") like "%${search}%"`) // This errors

sql.raw(`date_format(${MyTable.mycolumn.name}, "%d-%m-%Y") like "%${search}%"`) // This Works!
1 replies
DTDrizzle Team
Created by pedro77 on 12/19/2023 in #help
Can I use drizzle + mysql2 driver + middleware.ts (next.js)?
Is this combo possible? Is it edge compatible?
4 replies
DTDrizzle Team
Created by pedro77 on 6/6/2023 in #help
Top-level await is not available in the configured target environment ("node14")
import type { Config } from "drizzle-kit";

import { getDbUrl } from "./src";

export default {
schema: "./src/schema.ts",
out: "./.migrations",
connectionString: await getDbUrl(), // ERRORS HERE
} satisfies Config;
import type { Config } from "drizzle-kit";

import { getDbUrl } from "./src";

export default {
schema: "./src/schema.ts",
out: "./.migrations",
connectionString: await getDbUrl(), // ERRORS HERE
} satisfies Config;
Full description here: https://github.com/drizzle-team/drizzle-orm/issues/721 Is there a way to work around this?
6 replies
DTDrizzle Team
Created by pedro77 on 6/5/2023 in #help
Nullable self-reference table relation
typescript: No overload matches this call.
Overload 1 of 2, '(left: Aliased<null>, right: AnyColumn | Placeholder<string, any> | SQLWrapper | null): SQL<unknown>', gave the following error.
Argument of type 'MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>' is not assignable to parameter of type 'Aliased<null>'.
Type 'MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>' is missing the following properties from type 'Aliased<null>': sql, fieldAlias, getSQL
Overload 2 of 2, '(left: MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>, right: number | AnyColumn | Placeholder<...> | SQLWrapper): SQL<...>', gave the following error.
Argument of type 'null' is not assignable to parameter of type 'number | AnyColumn | Placeholder<string, any> | SQLWrapper'. [2769]
typescript: No overload matches this call.
Overload 1 of 2, '(left: Aliased<null>, right: AnyColumn | Placeholder<string, any> | SQLWrapper | null): SQL<unknown>', gave the following error.
Argument of type 'MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>' is not assignable to parameter of type 'Aliased<null>'.
Type 'MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>' is missing the following properties from type 'Aliased<null>': sql, fieldAlias, getSQL
Overload 2 of 2, '(left: MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>, right: number | AnyColumn | Placeholder<...> | SQLWrapper): SQL<...>', gave the following error.
Argument of type 'null' is not assignable to parameter of type 'number | AnyColumn | Placeholder<string, any> | SQLWrapper'. [2769]
My schema
import { relations } from "drizzle-orm";
import { int, mysqlTable, serial, varchar } from "drizzle-orm/mysql-core";

export const account = mysqlTable("account", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
parentId: int("parentId"),
});

export const accountRelations = relations(account, ({ one }) => ({
parent: one(account, {
fields: [account.parentId],
references: [account.id],
}),
}));
import { relations } from "drizzle-orm";
import { int, mysqlTable, serial, varchar } from "drizzle-orm/mysql-core";

export const account = mysqlTable("account", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
parentId: int("parentId"),
});

export const accountRelations = relations(account, ({ one }) => ({
parent: one(account, {
fields: [account.parentId],
references: [account.id],
}),
}));
Index.ts
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

import * as schema from "./schema";

const poolConnection = mysql.createPool({
host: "host",
user: "user",
database: "database",
password: "password",
});

export const db = drizzle(poolConnection, { schema });

await db.query.account.findMany({
where: (account, { eq }) => eq(account.parentId, null) // ERRORS HERE
})
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

import * as schema from "./schema";

const poolConnection = mysql.createPool({
host: "host",
user: "user",
database: "database",
password: "password",
});

export const db = drizzle(poolConnection, { schema });

await db.query.account.findMany({
where: (account, { eq }) => eq(account.parentId, null) // ERRORS HERE
})
I haven't put a .notNull() anywhere
10 replies
TTCTheo's Typesafe Cult
Created by pedro77 on 5/8/2023 in #questions
Revalidate prisma query in `page.ts` RSC
I'm getting the same data every time I visit this route.
import { prisma } from "@acme/db";
import EditForm from "./edit-form";

export default async function Page({ params }: { params: { id: string } }) {
const account = await prisma.account.findUnique({
where: {
id: Number(params.id),
}
})

if (!account) return "Account doesn't exist";

return <EditForm account={account} />;
}
import { prisma } from "@acme/db";
import EditForm from "./edit-form";

export default async function Page({ params }: { params: { id: string } }) {
const account = await prisma.account.findUnique({
where: {
id: Number(params.id),
}
})

if (!account) return "Account doesn't exist";

return <EditForm account={account} />;
}
Is there a way to revalidate prisma queries in a RSC?
46 replies