Replies: 3 comments
-
I was able to figure this out as following,
async function query(query: string, parameters: any[]) {
const rows = [];
let updated = 0;
for await (const stmt of sqlite3.statements(d, query)) {
let i = 0;
let columns;
for (const p of parameters) {
sqlite3.bind(stmt, ++i, p);
}
while(await sqlite3.step(stmt) === SQLite.SQLITE_ROW) {
columns ??= sqlite3.column_names(stmt);
const row = sqlite3.row(stmt);
const item = {};
for (let index = 0; index < columns.length; index++) {
const element = columns[index];
item[element] = row[index];
}
rows.push(item);
}
updated = sqlite3.changes(this.db);
}
return {
rows,
updated
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
See this discussion for changes in 1.0. In particular, see this section. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@rhashimoto Thanks, I did figure this out, however, I just posted an answer for reference. May be if you can add this snippet in readme it will be of great help. Also could you take a look and let me know if anything is missing, like closing or disposing anything? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In previous version, there was
prepare_v2
method exposed on sqlite3, now its no longer present.How to execute query with parameters as shown below?
Beta Was this translation helpful? Give feedback.
All reactions