-
Notifications
You must be signed in to change notification settings - Fork 37
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
Allow a type parameter for the row results #154
Conversation
249bf14
to
c5ea50c
Compare
c5ea50c
to
c31d98a
Compare
@@ -100,18 +98,9 @@ interface QueryResult { | |||
rows?: QueryResultRow[] | |||
} | |||
|
|||
type ExecuteAs = 'array' | 'object' | |||
|
|||
type ExecuteOptions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we still want to keep this because we want to limit the number of valid options passed into Execute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can only pass these options:
{ as?: 'object'; cast?: Cast } | { as: 'array'; cast?: Cast }
Anything else Typescript will complain:
261 const got = await connection.execute('SELECT 1 from dual;', null, { as: 'RANDOM' })
~~
dist/index.d.ts:95:9
95 as?: 'object';
~~
The expected type comes from property 'as' which is declared here on type '{ as?: "object"; cast?: (field: Field, value: string) => any; }'
dist/index.d.ts:99:9
99 as: 'array';
~~
The expected type comes from property 'as' which is declared here on type '{ as: "array"; cast?: (field: Field, value: string) => any; }'
Accept a type parameter for the
execute
function that represents the returned results. This should allow you to use any of these styles:It uses function overloading to differentiate between rows as object and rows as array.
Fixes #150
Fixes #71