-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to overload codec for SQL Row (client.querySQL() results)
This commit enables a `client.withCodecs({ sql_row: {...} })` call. Caveat: `toDatabase()` must be specified even though it's not currently possible to send rows as query arguments. Here's an example: res = await client .withCodecs({ sql_row: { fromDatabase(data, desc) { return Object.fromEntries( desc.names.map((key, index) => [key, data[index]]), ); }, toDatabase() { throw "cannot encode SQL record as a query argument"; }, }, }) .querySQL( ... ); Here we decode SQL rows into JS objects {colName: colValue}. Note that toDatabase() is specified, albeit, it's a no op and is there just to satisfy the type checker. Most likely we'll end up adding a more high level API for this, e.g. client.withSQLRowsAsObjects().querySQL(...) or client.withCodecs(gel.SQLRowsAsObjects).querySQL(...) Note that either of these APIs would allow to specialize unpacking SQL rows into objects inside the actual codec, for better performance. In any case, the underlying machinery for those future new APIs will likely be the one that this commit implements.
- Loading branch information
Showing
4 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters