DT
Join ServerDrizzle Team
help
MySQL (Planetscale): Cannot read properties of undefined (reading 'name')
Hi
Hopefully someone can help me. I'm getting the above error in my insert query.
I have no idea what I'm doing wrong...
Hopefully someone can help me. I'm getting the above error in my insert query.
try {
const sql = ctx.db.insert(ticketInvitations).values([
{
guestId: 1,
ticketTypeId: '6458eeb763aee9ab82d8b79b',
eventId: 1,
amount: 1,
status: 'pending' as const,
}
]).toSQL();
console.log(sql);
} catch (error) {
console.error(error);
}
I have no idea what I'm doing wrong...
Partial error stack:
TypeError: Cannot read properties of undefined (reading 'name')
at file:///path_to_repo/node_modules/.pnpm/drizzle-orm@0.25.4_x5zvu6yhqtclhFull error stack:
r76ddvo6x3wgi/node_modules/drizzle-orm/session-8a621f09.mjs:7:3805
at Array.map (<anonymous>)
at Y.buildInsertQuery (file:///path_to_repo/node_modules/.pnpm/drizzle-orm@0.25.4_x5zvu6yhqtclhr76ddvo6x3wgi/node_modules/drizzle-orm/session-8a621f09.mjs:7:3788)
at QueryPromise.getSQL (file:///path_to_repo/node_modules/.pnpm/drizzle-orm@0.25.4_x5zvu6yhqtclhr76ddvo6x3wgi/node_modules/drizzle-orm/session-8a621f09.mjs:1:3874)
at QueryPromise.toSQL (file:///path_to_repo/node_modules/.pnpm/drizzle-orm@0.25.4_x5zvu6yhqtclhr76ddvo6x3wgi/node_modules/drizzle-orm/session-8a621f09.mjs:1:3963)
at eval (webpack-internal:///(api)/./src/modules/guests/router.ts:159:140)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async resolveMiddleware (file:///path_to_repo/node_modules/.pnpm/@trpc+server@10.25.0/node_modules/@trpc/server/dist/index.mjs:416:30)
at async callRecursive (file:///path_to_repo/node_modules/.pnpm/@trpc+server@10.25.0/node_modules/@trpc/server/dist/index.mjs:452:32)
at async callRecursive (file:///path_to_repo/node_modules/.pnpm/@trpc+server@10.25.0/node_modules/@trpc/server/dist/index.mjs:452:32)
at async callRecursive (file:///path_to_repo/node_modules/.pnpm/@trpc+server@10.25.0/node_modules/@trpc/server/dist/index.mjs:452:32)
at async callRecursive (file:///path_to_repo/node_modules/.pnpm/@trpc+server@10.25.0/node_modules/@trpc/server/dist/index.mjs:452:32)
at async resolve (file:///path_to_repo/node_modules/.pnpm/@trpc+server@10.25.0/node_modules/@trpc/server/dist/index.mjs:482:24)
Can you show a code where you creating db?
yes
Sorry, had to split because of message limits.
export const ticketInvitations = mysqlTable('ticketInvitations', {
id: serial('id').primaryKey(),
guestId: int('guestId').notNull(),
eventId: int('eventId').notNull(),
ticketTypeId: varchar('ticketTypeId', { length: 256 }).notNull(),
// status: mysqlEnum('status', ['pending', 'accepted', 'declined']).notNull(),
// expiresAt: datetime('expiresAt'),
});
I mean db = drizzle(…)
ah, it's planetscale
import { connect } from '@planetscale/database';
import { drizzle } from 'drizzle-orm/planetscale-serverless';
const connection = connect({
host: process.env.DATABASE_HOST,
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
});
export const db = drizzle(connection);
do you have monorepo project?
do you have 1 or multiple drizzle-orm instances installed?
do you have 1 or multiple drizzle-orm instances installed?
i have a monorepo but it's the first app in it with drizzle-orm
other inserts seem to work fine. but i think i'll check again.
also, mysql:push is working
also, mysql:push is working
yep, just tried the following insert and that works:
ctx.db.insert(guests).values({ ...input, owner: ctx.identity.id });
// where input is of shape:
type input = {
firstName: string;
lastName: string;
email: string;
phone: string | null;
}
// and owner is a string
okey, so another table is working
I have 1 more question, could you please check if you have imported
serial
, int
, etc, from /mysql-core
for ticketInvitations
tablethe imports:
import type { InferModel } from 'drizzle-orm';
import {
datetime,
int,
mysqlEnum,
mysqlTable,
serial,
varchar,
} from 'drizzle-orm/mysql-core';
import { createInsertSchema, createSelectSchema } from 'drizzle-zod';
import { z } from 'zod';
a single file per schema. with zod schemas in it. (same as with the
guests
schema, just different name)I can't see a reason why it breaks
cc @Dan Kochetov maybe you can check when you'll have some time?
cc @Dan Kochetov maybe you can check when you'll have some time?
oh
ah, and i've tried
@beta
in the meantime. same errorI see, that in first example you are using array and in second just an object
could you check to run first query(that you have troubles with) without an array
just to check if array causing it
ah, yeah. i've tried
but i'll quickly try again
values[0]
as wellbut i'll quickly try again
const insert = values[0];
console.log('insert', insert);
try {
const sql = ctx.db.insert(ticketInvitations).values(insert).toSQL();
same issue
insert {
guestId: 1,
ticketTypeId: '6458eeb763aee7ab82c8b79b',
eventId: 1,
amount: 1
}
TypeError: Cannot read properties of undefined (reading 'name')
Could you try installing
drizzle-orm
in the monorepo root using -w
?i just found the issue
like in this second.
i'm stupid and forgot to define the amount column 🤦♂️
i'm stupid and forgot to define the amount column 🤦♂️
I'm so so sorry
That's ok
We actually need to improve the types there by not allowing unknown keys
We actually need to improve the types there by not allowing unknown keys
Glad it's sorted out
I'm so getting used to typesafety with this project (trpc, drizzle, zod).
And the error message doesn't mention amount. But stricter typing will easily be enough.
Again: Sorry!
Again: Sorry!