Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong examples in README #14

Open
giovannilondero opened this issue Aug 10, 2023 · 2 comments
Open

Wrong examples in README #14

giovannilondero opened this issue Aug 10, 2023 · 2 comments
Labels

Comments

@giovannilondero
Copy link

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);
}
  1. open function doesn't accept a string, but a { name: string; location?: string; } object

  2. rows might 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 QueryResult type)


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?

@giovannilondero
Copy link
Author

expo-sqlite implements the same structure actually: https://docs.expo.dev/versions/latest/sdk/sqlite/#sqlresultsetrowlist

@Montchy Montchy added the docs label Aug 14, 2023
@ospfranco
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants