Closed dyedgreen closed 3 years ago
Since this is strictly for performance only, we'd need to check if there are performance improvements, since otherwise the additional API surface is not worth anything, since the functionality already exists.
I had a few thoughts about this, and with the recent issue #135, I believe the current API can be improved as follows:
To sketch the interface a bit more:
class DB {
// ...
// equivalent to prepareQuery(); queryAll(); finalize();
query(sql: string, values?: Record<string, QueryParam> | Array<QueryParam>): Array<Array<any>>
prepareQuery(sql: string): PreparedQuery
// ...
}
interface RowIterator {
next(): IteratorResult<Array<any>>;
return(): IteratorResult<Array<any>>;
}
class PreparedQuery {
// ...
query(values?: Record<string, QueryParam> | Array<QueryParam>): RowIterator
queryAll(values?: Record<string, QueryParam> | Array<QueryParam>): Array<Array<any>>
queryOne(values?: Record<string, QueryParam> | Array<QueryParam>): Array<any>
execute(values?: Record<string, QueryParam> | Array<QueryParam>)
get columns(): Array<ColumnName>
}
The common patterns in other libraries are:
query
is probably fine/ has no performance difference)query
)This would be a performance only feature; since the existing
query
already fills all the existing cases:db.query(...) // ignores return value
let [firstRow] = db.query(...)
[...db.query(...)]
db.query(...)
Originally posted by @dyedgreen in https://github.com/dyedgreen/deno-sqlite/issues/14#issuecomment-847397847