Rihan
Rihan
Explore posts from servers
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
Is there any rough timeline for the new implementation?
11 replies
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
Ahh I see, thank you very much for letting me know 😃
11 replies
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
Also, it seems like any comments cannot be parsed within Miniflare's .exec() so my working example above only applies to deployed Workers, and not local development.
11 replies
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
The two queries I'm running (shown above) are separated with \n. Is it intentional that any individual query cannot span across multiple lines too? With the migrations example on docs (which is also my scenario), it'd be common to see multi-line queries within them for readability.
11 replies
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
Thank you for getting back to me 😃
11 replies
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
Making the CREATE TABLE statement into a single line:
{"count":2,"duration":0.555}
11 replies
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
No description
11 replies
CDCloudflare Developers
Created by Rihan on 10/21/2024 in #d1-database
I'm trying to run multiple SQL
Here's a minimal repro
CREATE TABLE IF NOT EXISTS hub_migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);`
CREATE TABLE IF NOT EXISTS hub_migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);`
export default {
async fetch(request, env) {
const { pathname } = new URL(request.url);

if (pathname === "/testing") {
const query = `-- Migration number: 0001 2024-10-21T06:45:41.702Z
CREATE TABLE todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
);

INSERT INTO hub_migrations (name) values ('0000_create-todos');
`

// const statement = env.DB.prepare(query)
// const result = await statement.raw()

const result = await env.DB.exec(query)
return Response.json(result);
}

return new Response("");
},
}
export default {
async fetch(request, env) {
const { pathname } = new URL(request.url);

if (pathname === "/testing") {
const query = `-- Migration number: 0001 2024-10-21T06:45:41.702Z
CREATE TABLE todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
);

INSERT INTO hub_migrations (name) values ('0000_create-todos');
`

// const statement = env.DB.prepare(query)
// const result = await statement.raw()

const result = await env.DB.exec(query)
return Response.json(result);
}

return new Response("");
},
}
11 replies