denodrivers / sqlite3

The fastest and correct SQLite3 module for Deno runtime
https://jsr.io/@db/sqlite
Apache License 2.0
265 stars 22 forks source link

Get one row as object #58

Closed korywka closed 2 years ago

korywka commented 2 years ago

Current .get returns an array, and you have to map keys and values again to create object.

Or something like that:

cosnt record = db
      .prepare("SELECT id, email, challenge FROM user WHERE id = ?")
      .all(user.id) as unknown as User[];
return record.length ? record[0] : null;

Maybe I have missed something in docs.

DjDeveloperr commented 2 years ago

Right now there's no specific method to get only one row as object, but that's something desirable to add. I wonder what such method should be named.

korywka commented 2 years ago

IMHO the naming is now a bit confusing: .get returns array and .all returns object. I expected them to return the same data structure (after using .get I expected .all to be array of arrays, but found bug and went to read the documentation).

Maybe the new naming will become a little more obvious.

DjDeveloperr commented 2 years ago

Maybe get should return object and value can be the new method with current behaviour of get.