subRows.map is not a function

I am getting a subRows.map is not a function error when adding the "with" parameter to my relational queries. here is my schema;
export const users = pgTable("users", {
id: serial("id").primaryKey(),

name: text("name"),
role: text("role").default("user"),
});

export const usersRelations = relations(users, ({ many }) => ({
parties: many(parties),
}));

export const parties = pgTable("parties", {
id: serial("id").primaryKey(),
partyName: text("party_name"),
authorId: integer("author_id"),
});

export const postsRelations = relations(parties, ({ one }) => ({
author: one(users, {
fields: [parties.authorId],
references: [users.id],
}),
}));
export const users = pgTable("users", {
id: serial("id").primaryKey(),

name: text("name"),
role: text("role").default("user"),
});

export const usersRelations = relations(users, ({ many }) => ({
parties: many(parties),
}));

export const parties = pgTable("parties", {
id: serial("id").primaryKey(),
partyName: text("party_name"),
authorId: integer("author_id"),
});

export const postsRelations = relations(parties, ({ one }) => ({
author: one(users, {
fields: [parties.authorId],
references: [users.id],
}),
}));
poyraz
poyraz•355d ago
cc @Dan Kochetov
const data = await db.query.users.findMany({
// @ts-ignore
where: (users, { eq }) => eq(users.id, 34),
with: {
parties: true,
},
});
const data = await db.query.users.findMany({
// @ts-ignore
where: (users, { eq }) => eq(users.id, 34),
with: {
parties: true,
},
});
errors with subRows.map is not a function
const data = await db.query.parties.findFirst({
// @ts-ignore
where: (parties, { eq }) => eq(parties.id, parseInt(id)),
with: {
author: true,
},
});
const data = await db.query.parties.findFirst({
// @ts-ignore
where: (parties, { eq }) => eq(parties.id, parseInt(id)),
with: {
author: true,
},
});
returns the party object with autor: null I use AWS Data API RDS running a postgresql11.13 engine
bloberenober
bloberenober•355d ago
will check
poyraz
poyraz•353d ago
any luck eith this cannot use relations bc of the error
bloberenober
bloberenober•353d ago
not yet, but will look into it shortly
poyraz
poyraz•353d ago
@Dan Kochetov i think i found the problem AWS-Data-api returns everything in objects such as { stringValue: "[]" }, and that is why subRows.map is not a function bc subRows is still a object doesn't drizzle handle objects returned by aws? bc now aws is only returning objects and it also makes it impossible for relations i imagine so strange thing, drizzle does handle this with old syntax like db.select().from(users), but doesnt whit relational queries
bloberenober
bloberenober•353d ago
Thanks for the investigation! I'll check it.
poyraz
poyraz•353d ago
{"data1":[{"id":{"longValue":34},"name":{"stringValue":"poyraz"}}],"data2":[{"id":34,"name":"poyraz"}]} data1 is db.query.users.findMany(), data2 is db.select().from(users)
bloberenober
bloberenober•353d ago
@poyraz could you test with drizzle-orm@0.26.3-0d21b8a?
poyraz
poyraz•353d ago
new error: Relation author not found
{"data1":[{"id":{"longValue":34},"name":{"stringValue":"poyraz"}}],"data2":[{"id":34,"name":"poyraz"}]}
{"data1":[{"id":{"longValue":34},"name":{"stringValue":"poyraz"}}],"data2":[{"id":34,"name":"poyraz"}]}
still the same data is being returned it is not getting parsed
bloberenober
bloberenober•353d ago
checking further the actual issue was I didn't extract the field values from the Data API format for relational queries. Had to spin up an instance to test properly nomore AWS won again Should be now fixed (for real) in drizzle-orm@0.26.3-af636c3 @poyraz
poyraz
poyraz•352d ago
Error: Cannot find module 'drizzle-orm/version' Require stack: - /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js at Module._resolveFilename (node:internal/modules/cjs/loader:995:15) new error cannot find drizzle-orm/version i am using sst btw i also cannot query any data from sst as it says package not found drizzle-orm maybe i did smth wrong will check it out later
bloberenober
bloberenober•352d ago
did you start seeing these errors after one of the recent updates, or are you setting up a new project?
poyraz
poyraz•352d ago
started seeing them after updating to af636c3 going back to latest drizzle version fixes the error 0.26.3 isnt throwing any erros
bloberenober
bloberenober•352d ago
did you install drizzle-orm and drizzle-kit in the monorepo root? sst uses a monorepo setup so currently you need to install drizzle in the root using -w
poyraz
poyraz•352d ago
i initiate the db through the core package do i still need to install drizzle and drizzle kit in root of monorepo downloading in root doesnt change much still same error and i dont think you need to install drizzle in root bc it was working just fine when i only had it installed in packages/core
bloberenober
bloberenober•352d ago
it might've happened because you installed another Drizzle version try removing all node_modules from the monorepo, removing drizzle-orm and drizzle-kit from package dependencies and adding them as monorepo root dependencies
poyraz
poyraz•352d ago
quick question does my drizzle.config.ts have to be in the root folder aswell
bloberenober
bloberenober•352d ago
no, but it'll be easier if it is, because drizzle-kit will detect it automatically
poyraz
poyraz•352d ago
so removed drizzle-kit and drizzle-orm from packages/core removed node modules installed using -w still same error throwing
drizzle-kit: v0.18.1

node:internal/modules/cjs/loader:995
const err = new Error(message);
^

Error: Cannot find module 'drizzle-orm/version'
Require stack:
- /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at assertOrmCoreVersion (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:50666:36)
at Command2.<anonymous> (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:51204:3)
at Command2.listener [as _actionHandler] (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:832:21)
at /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:1251:69
at Command2._chainOrCall (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:1183:16)
at Command2._parseCommand (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:1251:31) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js'
]
}

Node.js v18.12.1
drizzle-kit: v0.18.1

node:internal/modules/cjs/loader:995
const err = new Error(message);
^

Error: Cannot find module 'drizzle-orm/version'
Require stack:
- /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at assertOrmCoreVersion (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:50666:36)
at Command2.<anonymous> (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:51204:3)
at Command2.listener [as _actionHandler] (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:832:21)
at /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:1251:69
at Command2._chainOrCall (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:1183:16)
at Command2._parseCommand (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js:1251:31) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/drizzle-kit@0.18.1/node_modules/drizzle-kit/index.js'
]
}

Node.js v18.12.1
full error the command i am trying to run is pnpm drizzle-kit generate:pq Any updates on this? Pretty frustrating as i cannot use relations with aws-data-api 😦
bloberenober
bloberenober•352d ago
Not a lot of ideas at the moment honestly, @Andrew Sherman might take a look, since it might be kit-related
poyraz
poyraz•351d ago
thats a bummer, @Andrew Sherman any idea what could be causing this issue?
Andrii Sherman
Andrii Sherman•351d ago
I guess the best way to help me is if you can create a new GH repo with minimal reproducible example no need for code or anything, just as simplier as possible where this issue will appear then I can just clone it and try it myself
sammccord
sammccord•127d ago
👋 i've got an example where this pops up, but with bun and sqlite - https://github.com/sammccord/drizzle-relations-repro not sure if this is the best place to bring it up, or if it's an issue with bun and I should go there
GitHub
GitHub - sammccord/drizzle-relations-repro
Contribute to sammccord/drizzle-relations-repro development by creating an account on GitHub.
Want results from more Discord servers?
Add your server
More Posts
Postgres's Serial column type doesn't automatically have a defaultHello, when using postgres's `serial` types, and setting them as primary keys, there is an issue curHow to insert into a table without providing valuesI've got the following schema for users in sqlite, it only contains an id, which is an auto incremenDoent infer type in Callback syntax for queryIm querying the users table like this `db.query.user.findFirst({ where: (user, { eq }) => { Bug When Trying To Increment A Fieldthis set the field to 0 instead of increasing by one it used to work in other routes ``` await Maximum call stack exceeded with relation to selfI have the following table ``` export const category = pgTable('categories', { id: serial('id').importing into schema.ts fileHi, I am using turborepo and I have defined my schema in `packages/schema/user.ts` and in my main AWhat versions of MySQL are supported? I have JSON_ARRAYAGG issues with 5.7 and AWS Aurora ServerlessCan you confirm what versions of MySQL you intend on supporting? Relational queries with joins use J`$with` example in docs error "unsupported: with expression in select statement"I have a user with id of 42, just like the docs https://orm.drizzle.team/docs/crud#with-clause but Infer type for relational queryIs there anyway to infer the type of a relational queries result? For example if I have a user who in drizzle.config.ts: "Cannot use import statement outside a module"happens when I try to `push` ```ts import type { Config } from "drizzle-kit"; import { env } from "Error when using Drizzle (Non-abstract class 'PgSelect<TTableName, TSelection, TSelectMode, [...])I'm getting the following error when I try to use Drizzle: ```> graphql-server@1.0.0 start > npm runGenerate classes/interfaces from existing schemas?Messing around with drizzle, and I was wondering if there was any way to generate a class or interfaRelation Query - Get likes in postPlaying around with relational queries and I'm not quite getting how I'd retrieve the count of likesRelation query `extras` needs access to `with`I have a mysql table with two relations to another table. (one is for source values, one is for optiOptional filter param, coalesce to true?Is there a way to achieve this coalescing technique, but in valid drizzle sql? ```ts const filterByRelational query, Planetscale throws: `ResourceExhausted desc = Out of sort memory`SOLUTION: the problem was that I had a json column storing a massive value on each row. `code = ReInt to Float or Double db:pushHi we are working on a project that has drizzle db connected to a planetscale database. We initiallyTimestamp mode differences?What is the difference between the timestamp "mode" of "string'"and "date"?Many-to-Many Self RelationI'm looking to migrate from Prisma, but I'm having trouble trying to figure out how a many-to-many sRelations, three level nested where?Given a `User, Role, RoleToUser` many-to-many relation: ```ts export const userRelations = relation