```js

export default {
async fetch(request, env, ctx) {
let res = await env.MYDATABASE.exec("PRAGMA table_list")
console.log(res)
return Response.json({res: res})
},
};
export default {
async fetch(request, env, ctx) {
let res = await env.MYDATABASE.exec("PRAGMA table_list")
console.log(res)
return Response.json({res: res})
},
};
(TypeScript is transpiled into JavaScript before it is deployed, so there should be no difference)
15 Replies
captain
captain15mo ago
i'm using that later method, that said...i've used D1 in alpha and had it working in another part of my code block which I'm reviewing. I have added "vars" to my toml which is one change. Reviewing now the other feature in this project to see if it stopped working. But that said, the try/catch should be showing some sort of error in the console to possible describe what is happening and its not for some reason so just trying to see if there is some unknown set up issue that is not documented. In my code from about 4 days ago that is in production that is running the alpha, i could see entries being made last night so it was still running. Right now this is all in my dev channel of code standby..running some more tests. If i print the statement earlier in my codeblock its show...seeing where it stops okay...couple notes! i was messing up and forgot to add an "await" to for when I called the a function i set up for testing...oops so now things are operating kinda i can see the PRAGMA table_list however when an error should be generated via the try catch, the error is only showing: {} and no information is i the error (was testing the alpha) now going back to the beta @Matt did you make any changes, i'm now seeing database entries inserted. HOWEVER, in my console logs of the try catch, even though its inserting its still catching an error however the error message isn't showing, it just shows: {}
elithrar
elithrarOP15mo ago
Zero changes. I can’t change your code.
captain
captain15mo ago
i am asking if changes were made to d1
elithrar
elithrarOP15mo ago
No, we don’t make changes like that.
captain
captain15mo ago
okay, any idea why an error message is triggering but not showing? the code block looks like this, one second:
elithrar
elithrarOP15mo ago
Without seeing your code: no. It’s hard to debug if you are only giving part of the code - just like the await issue above, which wasn’t in the code you shared .
captain
captain15mo ago
(my appologies for that) let me just give you a small piece of code
console.log("we start the new DB");
try {
console.log("we start the new DB test 1");
/// the insert into db
var success1 = await env.MYTEST_DB.prepare(`
insert into messages (
location_id, time_stamp, status, customer_dismiss, status_type, title, body, amount, color, event_type, e_id,
i_id, o_id, s_id, p_id, c_id, service, email, name, location_name, link, related_locations, other) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?)
`).bind(restaurant_token_used, timestamp_index, 'new', 0, payment_or_notification, notification_message.title, notification_message.body, notification_message.amount, notification_message.color, event.type, event.id,
invoice_id, event.data.object.id, subscription_id, payment_id, customer_id, service, customer_email, customer_name, settings_response_parsed.location_account.location_name, message_link, "","").run()
} catch (e) {
console.log(" ERROR MESSAGE");
console.log(JSON.stringify(e))

}
console.log("we end the new DB");
console.log("we start the new DB");
try {
console.log("we start the new DB test 1");
/// the insert into db
var success1 = await env.MYTEST_DB.prepare(`
insert into messages (
location_id, time_stamp, status, customer_dismiss, status_type, title, body, amount, color, event_type, e_id,
i_id, o_id, s_id, p_id, c_id, service, email, name, location_name, link, related_locations, other) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?)
`).bind(restaurant_token_used, timestamp_index, 'new', 0, payment_or_notification, notification_message.title, notification_message.body, notification_message.amount, notification_message.color, event.type, event.id,
invoice_id, event.data.object.id, subscription_id, payment_id, customer_id, service, customer_email, customer_name, settings_response_parsed.location_account.location_name, message_link, "","").run()
} catch (e) {
console.log(" ERROR MESSAGE");
console.log(JSON.stringify(e))

}
console.log("we end the new DB");
as mentioned, this block actually does insert into the database but also is triggering a "catch" error however when printing out "e" it just prints out: {} also note the reason why it wasn't inserting before is that i haad forggoten to add a value in the binding...that said, it still possibly should have triggered an error message to say that
elithrar
elithrarOP15mo ago
And so you see the output from:
console.log(" ERROR MESSAGE");
console.log(" ERROR MESSAGE");
... but NOT:
console.log(JSON.stringify(e))
console.log(JSON.stringify(e))
captain
captain15mo ago
correct I am seeing ERROR MESSAGE my assumption is that there should be something in there correct I am seeing ERROR MESSAGE BUT...this: console.log(JSON.stringify(e)) is only printing: {} my assumption is that there should be something in there
elithrar
elithrarOP15mo ago
What version of wrangler are you using?
captain
captain15mo ago
i was using 3.9
elithrar
elithrarOP15mo ago
D1 client API · Cloudflare D1 docs
As part of our Client API, both static and prepared statements are supported. Best practice is to use prepared statements which are precompiled …
captain
captain15mo ago
okay I guess I just was assuming e would include all the json error messaging...but you are right it doesn't when i explicitly state e.message it then shows me the error...okay...thanks for gtting this all lined up...i will continue messing around, thank you Matt (sorry for being a pain in your ass...if you are in santa monica i owe you lunch, thanks for your patience!)
elithrar
elithrarOP15mo ago
Ha, no problems - happy to help. On the wrong side of the country (NYC) unfortunately!
captain
captain15mo ago
ahh got it, i learned something new! Thanks
Want results from more Discord servers?
Add your server