Chi Hao
Chi Hao
Explore posts from servers
DTDrizzle Team
Created by Chi Hao on 4/11/2024 in #help
update multiple rows is not working. PostgresError: column excluded.name does not exist
I'm trying to insert multiple rows and update onconflict for those rows that have conflict.
export type OrderPhases = {
restaurant_id: number;
uuid?: string;
name: string;
from: string;
to: string;
delivery_time: string;
};

export const updateRestaurantSettings = async (
orderPhaseValues: OrderPhases[],
deliveryLocationValues: { restaurant_id: number; location: string }[]
): Promise<void> => {
try {
await db.transaction(async (tx) => {
await db
.insert(order_phases)
.values(orderPhaseValues)
.onConflictDoUpdate({
target: order_phases.uuid,
set: {
name: sql.raw(`excluded.${order_phases.name.name}`),
from: sql.raw(`excluded.${order_phases.from.name}`),
to: sql.raw(`excluded.${order_phases.to.name}`),
delivery_time: sql.raw(`excluded.${order_phases.delivery_time.name}`),
},
});

await db.insert(delivery_location).values(deliveryLocationValues);
});
} catch (error) {
throw new Error("Error in updateRestaurant: " + error);
}
};
export type OrderPhases = {
restaurant_id: number;
uuid?: string;
name: string;
from: string;
to: string;
delivery_time: string;
};

export const updateRestaurantSettings = async (
orderPhaseValues: OrderPhases[],
deliveryLocationValues: { restaurant_id: number; location: string }[]
): Promise<void> => {
try {
await db.transaction(async (tx) => {
await db
.insert(order_phases)
.values(orderPhaseValues)
.onConflictDoUpdate({
target: order_phases.uuid,
set: {
name: sql.raw(`excluded.${order_phases.name.name}`),
from: sql.raw(`excluded.${order_phases.from.name}`),
to: sql.raw(`excluded.${order_phases.to.name}`),
delivery_time: sql.raw(`excluded.${order_phases.delivery_time.name}`),
},
});

await db.insert(delivery_location).values(deliveryLocationValues);
});
} catch (error) {
throw new Error("Error in updateRestaurant: " + error);
}
};
this is my schema for order_phases
export const order_phases = pgTable(
"Order_Phases",
{
id: serial("ID").notNull().primaryKey(),
restaurant_id: integer("Restaurant_ID")
.notNull()
.references(() => restaurants.id, { onDelete: "cascade" }),
uuid: uuid("UUID").defaultRandom().unique(),
name: text("Name").notNull(),
from: text("From").notNull(),
to: text("To").notNull(),
delivery_time: text("Delivery_Time").notNull(),
},
(t) => ({
unq: unique().on(t.restaurant_id, t.name),
})
);
export const order_phases = pgTable(
"Order_Phases",
{
id: serial("ID").notNull().primaryKey(),
restaurant_id: integer("Restaurant_ID")
.notNull()
.references(() => restaurants.id, { onDelete: "cascade" }),
uuid: uuid("UUID").defaultRandom().unique(),
name: text("Name").notNull(),
from: text("From").notNull(),
to: text("To").notNull(),
delivery_time: text("Delivery_Time").notNull(),
},
(t) => ({
unq: unique().on(t.restaurant_id, t.name),
})
);
I wonder if I'm using excluded wrongly?
6 replies
DTDrizzle Team
Created by Chi Hao on 4/1/2024 in #help
How do I reuse the results from the where clause within the findMany?
I have a vendor ID and want to retrieve all restaurant IDs and menu IDs associated with that vendor. Can I use the same ID I passed in the where clause for menus as the value for the restaurant ID received in the first where clause?
7 replies
DTDrizzle Team
Created by Chi Hao on 3/28/2024 in #help
How to use findMany?
I'm using supabase. I'm going to show a sample which doesnt necessarily need findMany to work but I would like to know how to use it as I'm unable to do it.
7 replies
DTDrizzle Team
Created by Chi Hao on 3/9/2024 in #help
Connection timeout when connecting supabase to astro project while using Drizzle kit
this is the issue I ran into
PS C:\Users\User\Desktop\folder> pnpm run db:push

> [email protected] db:push C:\Users\User\Desktop\folder
> drizzle-kit push:pg

drizzle-kit: v0.20.14
drizzle-orm: v0.30.0

No config path provided, using default path
Reading config file 'C:\Users\User\Desktop\folder\drizzle.config.ts'
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

Error: connect ETIMEDOUT XXX.XXX.XXX.XXX:5432
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:671:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: 'XXX.XXX.XXX.XXX',
port: 5432
}

Node.js v18.18.0
 ELIFECYCLE  Command failed with exit code 1.
PS C:\Users\User\Desktop\folder> pnpm run db:push

> [email protected] db:push C:\Users\User\Desktop\folder
> drizzle-kit push:pg

drizzle-kit: v0.20.14
drizzle-orm: v0.30.0

No config path provided, using default path
Reading config file 'C:\Users\User\Desktop\folder\drizzle.config.ts'
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

Error: connect ETIMEDOUT XXX.XXX.XXX.XXX:5432
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:671:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: 'XXX.XXX.XXX.XXX',
port: 5432
}

Node.js v18.18.0
 ELIFECYCLE  Command failed with exit code 1.
4 replies