kysely icon indicating copy to clipboard operation
kysely copied to clipboard

A way to disable 'preventAwait'

Open wirekang opened this issue 8 months ago • 7 comments

Although @koskimas closed #693 as 'wontfix', I'm suggesting a way to disable the behavior of preventAwait, with a small footprint. We often returning non-Promise value in async function or then() chains. It would be great if Kysely have an option for those situation, for people who aren't Knex-newbie or know how to execute query.

The name 'allowNoopAwait' is a little bit temporary, it can be renamed as 'allowAwait', 'ignoreAwait', 'disablePreventAwait', 'iKnowHowToExecute' or something you suggest.

wirekang avatar Oct 26 '23 02:10 wirekang

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 14, 2024 9:25am

vercel[bot] avatar Oct 26 '23 02:10 vercel[bot]

Hey 👋

We often returning non-Promise value in async function or then() chains. It would be great if Kysely have an option for those situation

I didn't get the necessity quite honestly. Can you elaborate on that?

igalklebanov avatar Nov 07 '23 10:11 igalklebanov

I didn't get the necessity quite honestly. Can you elaborate on that?

The code from original issue #693, and I'm not sure I can find better example.. Yeah it is not "often" but "rarely", sorry for overstating. But it worth considering turning off the behavior that throwing error without actual logical reason.

wirekang avatar Nov 08 '23 02:11 wirekang

But it worth considering turning off the behavior that throwing error without actual logical reason.

There is a logical reason. People coming from knex and objection would make the mistake of awaiting queries without execute. Kysely is heavily inspired by knex which naturally leads people thinking it behaves the same.

koskimas avatar Nov 09 '23 12:11 koskimas

There is a logical reason. People coming from knex and objection would make the mistake of awaiting queries without execute. Kysely is heavily inspired by knex which naturally leads people thinking it behaves the same.

@koskimas I didn't denied it. I meant "programming logic error". Anyways, It was a light suggestion, never mind.

wirekang avatar Nov 10 '23 01:11 wirekang

I think it wouldn't hurt to add this. But remove the delete clazz.prototype.then thing. Having a simple then method that simply values through when prevent = false shouldn't have any measurable effect on performance.

Edit: Or actually, will that cause infinite recursion? Does resolve call .then?

koskimas avatar Jan 13 '24 09:01 koskimas

@koskimas Yes. That was the reason I have to delete then.

wirekang avatar Jan 14 '24 08:01 wirekang