I just wanted to write my problem Thanks for your help
I just wanted to write my problem
Thanks for your help
Thanks for your help
wrangler.toml file
all() returns a D1Result objectconst { results } = await stmt.all(); to grab just the results propertyconst { results } = await stmt.all();results will be an empty array if there were no results, or null if it doesn't apply (that query doesn't return anything).
npx wrangler d1 execute or npx wrangler d1 migrations apply name = "foxes"
main = "src/index.js"
compatibility_date = "2023-05-18"
[[d1_databases]]
binding = "DB"
database_name = "foxes"
database_id = "im-not-sure-if-its-safe-to-share-it"all()const { results } = await stmt.all();const { results } = await stmt.all();resultsresultsnullnpx wrangler d1 executenpx wrangler d1 migrations applyexport interface Env {
DB: D1Database;
}
export default {
async fetch(request: Request, env: Env) {
const stmt = env.DB.prepare(`SELECT time FROM (SELECT time, count(*) as cnt FROM accesslog WHERE ip = ?1 GROUP BY time) WHERE cnt >= 3`).bind("81.213.254.29");
const results = await stmt.all();
return Response.json(results);
},
};const results = await stmt.all();
if (results.length > 0) {const { results } = await stmt.all();
if (results && results.length > 0) {