Chi Hao
Chi Hao
Explore posts from servers
HHono
Created by Chi Hao on 6/4/2024 in #help
unable to retrieve cookie value
// index.ts
import { Hono } from 'hono';
import { getCookie, setCookie} from 'hono/cookie';
import CryptoJS from 'crypto-js';

const app = new Hono();

app.get('/csrf', (c) => {
setCookie(c, 'X-CSRF-Token', 'abc');
const testget = getCookie(c, 'X-CSRF-Token');
console.log('test get: ', testget);

const allCookies = getCookie(c);
console.log('allCookies : ', allCookies);

return c.text(csrfToken);
});

export default app;
// index.ts
import { Hono } from 'hono';
import { getCookie, setCookie} from 'hono/cookie';
import CryptoJS from 'crypto-js';

const app = new Hono();

app.get('/csrf', (c) => {
setCookie(c, 'X-CSRF-Token', 'abc');
const testget = getCookie(c, 'X-CSRF-Token');
console.log('test get: ', testget);

const allCookies = getCookie(c);
console.log('allCookies : ', allCookies);

return c.text(csrfToken);
});

export default app;
this is the log
test get: undefined
allCookies : {}
[wrangler:inf] GET /csrf 200 OK (8ms)
test get: undefined
allCookies : {}
[wrangler:inf] GET /csrf 200 OK (8ms)
41 replies
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

> folder@0.0.1 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

> folder@0.0.1 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