ts-sql-plugin icon indicating copy to clipboard operation
ts-sql-plugin copied to clipboard

Document `mock`

Open rattrayalex opened this issue 4 years ago • 5 comments

This seems like an awesome tool but I am a little confused trying to figure out how to use it from reading the README alone.

Can you explain more what is sql.mock<X>?

rattrayalex avatar Apr 19 '21 17:04 rattrayalex

Example:

sql`select * from users where user_id = ${sql.mock<'1'>(userId)}`

Here in compile time you receive:

select * from users where user_id = 1

In runtime:

select * from users where user_id = $1


sql.mock helps to "mock" placeholders for compile time. Cost of queries will be more precise in this case.

darky avatar Apr 19 '21 18:04 darky

Got it. Very cool technique. Would you like me to add that to the readme?

rattrayalex avatar Apr 19 '21 18:04 rattrayalex

Actually, I might be interested in rewriting the readme to be more explicit and explain more things, if you would like that? Right now, I feel you probably need to download and run the tool to really understand it, which might be a barrier to adoption.

rattrayalex avatar Apr 19 '21 18:04 rattrayalex

Yep, contribution welcome! Thanks!

darky avatar Apr 19 '21 18:04 darky

Okay, thanks, I'll try to take a look at reworking the readme soon!

rattrayalex avatar Apr 19 '21 18:04 rattrayalex