Wrong examples in README
Hi,
Library version
8.0.4
Issue
README contains wrong examples of using the library (or the types need to be reviewed, you decide).
If we take the Simple queries example:
try {
const db = open('myDb.sqlite');
const { rows } = db.execute('SELECT somevalue FROM sometable');
rows.forEach((row) => {
console.log(row);
});
let { rowsAffected } = await db.executeAsync(
'UPDATE sometable SET somecolumn = ? where somekey = ?',
[0, 1],
);
console.log(`Update affected ${rowsAffected} rows`);
} catch (e) {
console.error('Something went wrong executing SQL commands:', e.message);
}
-
openfunction doesn't accept a string, but a{ name: string; location?: string; }object -
rowsmight be undefined and is not an array, it's:rows?: { /** Raw array with all dataset */ _array: any[]; /** The lengh of the dataset */ length: number; /** A convenience function to acess the index based the row object * @param idx the row index * @returns the row structure identified by column names */ item: (idx: number) => any; };(taken from the
QueryResulttype)
I would expect rows to be an array, so I'd like the types to be reviewed, but I'm not sure it's in scope.
Fixing the examples is quicker, for sure.
Interestingly, no one else complained; the same code is present in the old repo.
What do you think?
expo-sqlite implements the same structure actually: https://docs.expo.dev/versions/latest/sdk/sqlite/#sqlresultsetrowlist
You are right insofar that the example in the readme is wrong. That was from the first implementation. The API however is complaint to webSQL, that's also why expo-sqlite also returns it. webSQL is dead though, so the specification is only for legacy purposes as a lot of libraries consume it.