Pachimari
Pachimari
DTDrizzle Team
Created by Pachimari on 8/15/2023 in #help
TypeError: Cannot read properties of undefined (reading 'referencedTable')
Here is the relational query that I'm trying to execute (Turso SQLite):
const result = db.query.product
.findMany({
where: (product) => inArray(product.id, keys),
with: {
seller: true,
},
})
.execute();
const result = db.query.product
.findMany({
where: (product) => inArray(product.id, keys),
with: {
seller: true,
},
})
.execute();
Here is the schema:
export const product = sqliteTable(
"product",
{
id: text("id").notNull().primaryKey(),
...
sellerId: text("sellerId")
.notNull()
.references(() => user.id),
},
(product) => ({
sellerIdx: index("sellerIdx").on(product.sellerId),
}),
);
export const product = sqliteTable(
"product",
{
id: text("id").notNull().primaryKey(),
...
sellerId: text("sellerId")
.notNull()
.references(() => user.id),
},
(product) => ({
sellerIdx: index("sellerIdx").on(product.sellerId),
}),
);
export const user = sqliteTable(
"user",
{

id: text("id").notNull().primaryKey(),
}).notNull(),
...
},
(user) => ({
nameIdx: uniqueIndex("nameIdx").on(user.name),
}),
);
export const user = sqliteTable(
"user",
{

id: text("id").notNull().primaryKey(),
}).notNull(),
...
},
(user) => ({
nameIdx: uniqueIndex("nameIdx").on(user.name),
}),
);
export const productRelations = relations(product, ({ one, many }) => ({
seller: one(user, {
fields: [product.sellerId],
references: [user.id],
}),
}));
export const productRelations = relations(product, ({ one, many }) => ({
seller: one(user, {
fields: [product.sellerId],
references: [user.id],
}),
}));
export const userRelations = relations(user, ({ one, many }) => ({
products: many(product),
}));
export const userRelations = relations(user, ({ one, many }) => ({
products: many(product),
}));
Everytime I run relational query "with:{seller:true}" it throws error. In Drizzlekit studio, the product references seller just fine. What's wrong?
8 replies
DTDrizzle Team
Created by Pachimari on 8/13/2023 in #help
Is drizzle edge compatible (noobie question)?
Hi, I'm new to drizzle. I tried to set up a drizzle client with turso in cloudflare workers and I get these errors:
[ERROR] Could not resolve "node:buffer"

../../node_modules/@libsql/client/lib-esm/sqlite3.js:2:23:
2 │ import { Buffer } from "node:buffer";
╵ ~~~~~~~~~~~~~

The package "node:buffer" wasn't found on the file system but is built into node. Are you
trying to bundle for node? You can use "platform: 'node'" to do that, which will remove
this error.

✘ [ERROR] Could not resolve "fs"

../../node_modules/better-sqlite3/lib/database.js:2:19:
2 │ const fs = require('fs');
[ERROR] Could not resolve "node:buffer"

../../node_modules/@libsql/client/lib-esm/sqlite3.js:2:23:
2 │ import { Buffer } from "node:buffer";
╵ ~~~~~~~~~~~~~

The package "node:buffer" wasn't found on the file system but is built into node. Are you
trying to bundle for node? You can use "platform: 'node'" to do that, which will remove
this error.

✘ [ERROR] Could not resolve "fs"

../../node_modules/better-sqlite3/lib/database.js:2:19:
2 │ const fs = require('fs');
here is my db configuration
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";

import { env } from "../env";

const client = createClient({
url: env.DATABASE_URL,
authToken: env.DATABASE_AUTH_TOKEN,
});

export const db = drizzle(client, {
});
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";

import { env } from "../env";

const client = createClient({
url: env.DATABASE_URL,
authToken: env.DATABASE_AUTH_TOKEN,
});

export const db = drizzle(client, {
});
😓
3 replies