Mike J
Mike J
Explore posts from servers
DTDrizzle Team
Created by Mike J on 10/26/2024 in #help
How would you write this SQL query using Drizzle?
I realise I have made this more complicated than it needs to be. Because I expect select to return something most of the time, it's far simpler to just do a select and if I get null do a second query to insert. The COALESCE didn't do what I thought it doesn't stop the CTE being executed
2 replies
DTDrizzle Team
Created by DragonCoder99 on 10/18/2024 in #help
Using UUID v7 with Drizzle?
Hey @DragonCoder99 This has been fine for me in my schema.ts:
export const clients = pgTable("clients", {
id: uuid("id").primaryKey().default(sql`uuid_generate_v7()`)
});
export const clients = pgTable("clients", {
id: uuid("id").primaryKey().default(sql`uuid_generate_v7()`)
});
Don't forget to add the extension first e.g.
CREATE extension pg_uuidv7;
CREATE extension pg_uuidv7;
3 replies
CDCloudflare Developers
Created by Bamboo on 5/11/2023 in #workers-help
Connecting to CockroachDB serverless using pg via workers
The error I get on deploy is The package "net" 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.
5 replies
CDCloudflare Developers
Created by Bamboo on 5/11/2023 in #workers-help
Connecting to CockroachDB serverless using pg via workers
Great! Thanks. QQ - I am trying to deploy using Astro (so pages rather than a Worker). I want to use pg in an API route like below. Where do I specify I want to use Node compatibility? I see Settings -> Functions -> Compatibility flags in the dashboard UI. I guess I am not clear on 1. Do I just add node_compat in the UI? (or is it nodejs_compt) 2. Have I actually understood the process correctly that an Astro API route will be converted to a Pages Function?
import { Client } from "pg";

export async function GET({ params, request }) {
const DATABASE_URL = new URL(request.url).searchParams.get("database_url");
const client = new Client({ DATABASE_URL });
await client.connect();
await client.query("SELECT 1;");
await client.end();
return new Response(
JSON.stringify({
DATABASE_URL: DATABASE_URL,
})
);
}
import { Client } from "pg";

export async function GET({ params, request }) {
const DATABASE_URL = new URL(request.url).searchParams.get("database_url");
const client = new Client({ DATABASE_URL });
await client.connect();
await client.query("SELECT 1;");
await client.end();
return new Response(
JSON.stringify({
DATABASE_URL: DATABASE_URL,
})
);
}
5 replies
CDCloudflare Developers
Created by Bamboo on 5/11/2023 in #workers-help
Connecting to CockroachDB serverless using pg via workers
5 replies