CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 64 forks source link

Add typescript example and improve types #165

Closed kormic closed 2 years ago

kormic commented 2 years ago
move-zig commented 2 years ago

This looks good! I know other libraries like RxJS and axios use this pattern and I've found it to be pretty useful.

I wonder if we can clean up the generic a bit when returnArgumentsArray is true. Rather than the developer having to remember to correctly type the tuple, we could provide a helper type like

type ArgumentsArray<T> = [ data: T[], fields: FieldInfo[], query: Query<T> ];

Then the developer only has to write

connection.query<ArgumentsArray<Employee>>('select * from employees limit 0, 10')

rather than

connection.query<[data: Employee[], fields: FieldInfo[], query: Query<Employee>]>('select * from employees limit 0, 10')
kormic commented 2 years ago

@move-zig yes sure, that makes sense!

Edit: this way there is no need to re-export the type FieldInfo

CodeFoodPixels commented 2 years ago

Thank you both @kormic and @move-zig for your work on this!

CodeFoodPixels commented 2 years ago

Published as 5.2.0