achesui
achesui
Explore posts from servers
DTDrizzle Team
Created by achesui on 9/4/2024 in #help
PLEASE HELP WITH SQL OPERATOR DYNAMIC PARAMS
Hello, Im trying to execute a SQL query using SQL operator but it gives error. NeonDbError: syntax error at or near "$2" const treshold: number = 0; const hourProposal = "16:40:00"; const slotInterval = 30; const appointmentFrom = 1; const appointmentDay = "2024-09-05"; const initialHour = "10:00"; const finalHour = "17:00"; const availableAppointments: { rows: Appointment[] } = await db.execute(sql SELECT gs::time AS available_slot FROM generate_series( ${appointmentDay} ${initialHour}::timestamp, ${appointmentDay} ${finalHour}::timestamp - '${slotInterval} minutes'::interval, ${slotInterval} minutes::interval ) AS gs LEFT JOIN "create-appointment" ca ON gs::time = ca."appointment-hour" AND ca."appointment-day" = ${appointmentDay} AND ca."appointment-from" = ${appointmentFrom} WHERE ca."appointment-hour" IS NULL AND gs::time >= '${currentTime}'::time AND NOT EXISTS ( SELECT 1 FROM "create-appointment" ca2 WHERE ca2."appointment-day" = '${appointmentDay}' AND ca2."appointment-from" = ${appointmentFrom} AND ABS(EXTRACT(EPOCH FROM (gs::time - ca2."appointment-hour"))) < ${slotInterval} * 60 ); ); Thanks!
1 replies
CDCloudflare Developers
Created by achesui on 11/3/2023 in #pages-help
Websockets with NextJS
Hello, im new in cloudflare workers, i'm just trying to achieve the following thing: in Nextjs send some data to the cloudflare worker through websockets: --------------------------------------------------------------------------- NEXTJS (CLIENT SIDE): let websocket = new WebSocket("ws://xxxxxxxx.workers.dev/") if (!websocket) { throw new Error("Server didn't accept WebSocket") } when the cloudflare worker receives it, it should process some code calling a template html: --------------------------------------------------------------------------- CLOUDFLARE WORKER (index.js): import HTML from "example.html"; export default { async fetch(request, env) { const upgradeHeader = request.headers.get('Upgrade'); if (!upgradeHeader || upgradeHeader !== 'websocket') { return new Response('Expected Upgrade: websocket', { status: 426 }); } return new Response(HTML, {headers: {"Content-Type": "text/html;charset=UTF-8"}}); } } --------------------------------------------------------------------------- CLOUDFLARE WORKER (example.html): <!DOCTYPE html> <html> <body> <script> // After processing some code it returns a response to the nextjs client.... const webSocketPair = new WebSocketPair(); const client = webSocketPair[0], server = webSocketPair[1]; server.accept(); server.addEventListener('message', event => { console.log(event.data); }); </script> </body> </html> --------------------------------------------------------------------------- This is my code but im getting this error: Expected Upgrade: websocket (426) Thats the error in the cloudflare worker if there is not upgradeHeader, why is this happening?, im just trying to set a simple connection between nextJS and cloudflare workers, could you guys help me with an example?, just send a "hello world" from the client (nextjs) and return an "hello" from the server (cloudflare worker) ty
1 replies