mw10013
mw10013
Explore posts from servers
CDCloudflare Developers
Created by mw10013 on 6/7/2024 in #pages-help
How to troubleshoot deploy error: `Script startup exceeded CPU time limit`
No description
3 replies
DTDrizzle Team
Created by mw10013 on 5/8/2024 in #help
`sql` in D1 batch causes "TypeError: Cannot read properties of undefined (reading 'bind')"
Using sql in D1 batch causes "TypeError: Cannot read properties of undefined (reading 'bind')"
const upsertSql = sql`insert into ${schema.subscriptions}
(id, status, plan, cycle_started_at, customer_id, created_at, updated_at)
values (${subscriptionData.id}, ${subscriptionData.status}, ${plan}, ${cycleStartedAt.getTime()}, ${subscriptionData.customerId}, ${createdAt.getTime()}, ${updatedAt.getTime()})
on conflict (${schema.subscriptions.id}) do update set status = ${subscriptionData.status}, plan = ${plan}, cycle_started_at = ${cycleStartedAt.getTime()}, updated_at = ${updatedAt.getTime()}
where ${updatedAt.getTime()} > ${schema.subscriptions.updatedAt}
on conflict (${schema.subscriptions.customerId}) do update set id = ${subscriptionData.id}, status = ${subscriptionData.status}, plan = ${plan}, cycle_started_at = ${cycleStartedAt.getTime()}, created_at = ${createdAt.getTime()}, updated_at = ${updatedAt.getTime()}
where ${createdAt.getTime()} > ${schema.subscriptions.createdAt}
returning *`;

const [[batchSubscription]] = await db.batch([
db.all<schema.Subscription>(upsertSql),
]);
const upsertSql = sql`insert into ${schema.subscriptions}
(id, status, plan, cycle_started_at, customer_id, created_at, updated_at)
values (${subscriptionData.id}, ${subscriptionData.status}, ${plan}, ${cycleStartedAt.getTime()}, ${subscriptionData.customerId}, ${createdAt.getTime()}, ${updatedAt.getTime()})
on conflict (${schema.subscriptions.id}) do update set status = ${subscriptionData.status}, plan = ${plan}, cycle_started_at = ${cycleStartedAt.getTime()}, updated_at = ${updatedAt.getTime()}
where ${updatedAt.getTime()} > ${schema.subscriptions.updatedAt}
on conflict (${schema.subscriptions.customerId}) do update set id = ${subscriptionData.id}, status = ${subscriptionData.status}, plan = ${plan}, cycle_started_at = ${cycleStartedAt.getTime()}, created_at = ${createdAt.getTime()}, updated_at = ${updatedAt.getTime()}
where ${createdAt.getTime()} > ${schema.subscriptions.createdAt}
returning *`;

const [[batchSubscription]] = await db.batch([
db.all<schema.Subscription>(upsertSql),
]);
Running the sql outside of batch works fine.
const [subscription] = await db.all<schema.Subscription>(upsertSql);
const [subscription] = await db.all<schema.Subscription>(upsertSql);
Has anybody gotten sql to work inside of D1 batch?
1 replies
DTDrizzle Team
Created by mw10013 on 5/8/2024 in #help
Multiple onConflictDoUpdate's supported?
I'm using two onConflictDoUpdate() and seems only the last one is picked up when run. Are multiple onConflictDoUpdate supported?
const [subscription] = await db
.insert(schema.subscriptions)
.values({
id: subscriptionData.id,
status: subscriptionData.status,
plan,
cycleStartedAt,
customerId: subscriptionData.customerId,
createdAt,
updatedAt,
})
.onConflictDoUpdate({
target: schema.subscriptions.id,
set: {
status: subscriptionData.status,
plan,
cycleStartedAt,
updatedAt,
},
setWhere: sql`${updatedAt.getTime()} > ${schema.subscriptions.updatedAt}`,
})
.onConflictDoUpdate({
target: schema.subscriptions.customerId,
set: {
id: subscriptionData.id,
status: subscriptionData.status,
plan,
cycleStartedAt,
createdAt,
updatedAt,
},
setWhere: sql`${createdAt.getTime()} > ${schema.subscriptions.createdAt}`,
})
.returning();
const [subscription] = await db
.insert(schema.subscriptions)
.values({
id: subscriptionData.id,
status: subscriptionData.status,
plan,
cycleStartedAt,
customerId: subscriptionData.customerId,
createdAt,
updatedAt,
})
.onConflictDoUpdate({
target: schema.subscriptions.id,
set: {
status: subscriptionData.status,
plan,
cycleStartedAt,
updatedAt,
},
setWhere: sql`${updatedAt.getTime()} > ${schema.subscriptions.updatedAt}`,
})
.onConflictDoUpdate({
target: schema.subscriptions.customerId,
set: {
id: subscriptionData.id,
status: subscriptionData.status,
plan,
cycleStartedAt,
createdAt,
updatedAt,
},
setWhere: sql`${createdAt.getTime()} > ${schema.subscriptions.createdAt}`,
})
.returning();
insert into "subscriptions" ("id", "status", "plan", "cycle_started_at", "customer_id", "created_at", "updated_at")
values (?, ?, ?, ?, ?, ?, ?)
on conflict ("subscriptions"."customer_id")
do update set "id" = ?, "status" = ?, "plan" = ?, "cycle_started_at" = ?, "created_at" = ?, "updated_at" = ?
where ? > "subscriptions"."created_at" returning "id", "status", "plan", "cycle_started_at", "customer_id", "created_at", "updated_at"
insert into "subscriptions" ("id", "status", "plan", "cycle_started_at", "customer_id", "created_at", "updated_at")
values (?, ?, ?, ?, ?, ?, ?)
on conflict ("subscriptions"."customer_id")
do update set "id" = ?, "status" = ?, "plan" = ?, "cycle_started_at" = ?, "created_at" = ?, "updated_at" = ?
where ? > "subscriptions"."created_at" returning "id", "status", "plan", "cycle_started_at", "customer_id", "created_at", "updated_at"
5 replies
CDCloudflare Developers
Created by mw10013 on 4/4/2024 in #pages-help
Workers paid plan permit pages deploys up to 10MB in size?
Does the workers paid plan ($5/mo) permit pages deploys up to 10mb in size? Or do you need to get the cloudflare pro plan ($20/mo)? The pages limits page (https://developers.cloudflare.com/pages/platform/limits/) does not mention a size for the pages function. The workes limits page (https://developers.cloudflare.com/workers/platform/limits/) mentions 10mb for workers paid plan.
2 replies
CDCloudflare Developers
Created by mw10013 on 12/14/2023 in #workers-help
Can Workers Function use npm packages that use node apis?
I want to use the npm package thirty-two (https://www.npmjs.com/package/thirty-two). It was last published 7 years ago seems to use the Buffer api in node. In wrangler.toml, setting compatibility_flags = [ "nodejs_compat" ] was not enough. I also had to mutate globalThis. Is there a cleaner way to do this? What is the recommended approach to using npm packages that use node apis without an import with the node specifier (eg. import { Buffer } from 'node:buffer)
import * as base32 from 'thirty-two';
import { Buffer } from 'node:buffer';

export default {
async fetch(request: Request, env: {}, ctx: ExecutionContext): Promise<Response> {
globalThis.Buffer = Buffer;
const data = {
encode: base32.encode('node').toString(),
decode: base32.decode('NZXWIZI=').toString(),
};
return new Response(JSON.stringify(data, null, 2));
},
};
import * as base32 from 'thirty-two';
import { Buffer } from 'node:buffer';

export default {
async fetch(request: Request, env: {}, ctx: ExecutionContext): Promise<Response> {
globalThis.Buffer = Buffer;
const data = {
encode: base32.encode('node').toString(),
decode: base32.decode('NZXWIZI=').toString(),
};
return new Response(JSON.stringify(data, null, 2));
},
};
1 replies
CDCloudflare Developers
Created by mw10013 on 12/14/2023 in #workers-help
Workers Playground: load npm packages and specify nodejs_compat compatibility_flags?
Does the Workers Playground have a way to load npm packages and specify nodejs_compat as a compatibility_flag?
2 replies