#Cannot make D1 requests twice?

1 messages · Page 1 of 1 (latest)

candid moon
#

I am facing a strange issue where I am unable to make D1 queries multiple times. Here is the code I am using
```let sqlQuery = SELECT sura, aya, text FROM en_pickthall WHERE 1=1 ;
keywords.forEach((keyword, index) => {
sqlQuery += AND (;
sqlQuery += text LIKE '% ${keyword} %' ;
sqlQuery += OR text LIKE '% ${keyword}.' ;
sqlQuery += OR text LIKE '% ${keyword},' ;
sqlQuery += OR text LIKE '% ${keyword}?' ;
sqlQuery += OR text LIKE '% ${keyword}!' ;
sqlQuery += OR text LIKE '% ${keyword}%' ;
sqlQuery += ) ;
});
sqlQuery += LIMIT ${limit};;

                // Execute the query
                let { results } = await env.DB.prepare(sqlQuery).all();
                console.log(results)
                let { contextVerses } = await env.DB.prepare(sqlQuery).all();
                console.log(contextVerses);
If I run this code the console shows the first log is normal, but the second console.log returns undefined. What is going on here and how do I fix it?
crimson mural
#

Because contextVerses doesn’t exist on a D1Result I assume? You’re destructuring.

candid moon
#

Why does it work on one var and not the other when they are exactly the sam except for names?

#

okay declaring the var with {} and then accessing .results yields the correct value, but im still really confused on why this is happening

crimson mural
#

Because you’re destructuring, you’re accessing a property - and “contextVerses” isn’t a property