Skip to content
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

Prepared statements and async execution #110

Closed
chvllad opened this issue Jun 21, 2024 · 9 comments
Closed

Prepared statements and async execution #110

chvllad opened this issue Jun 21, 2024 · 9 comments

Comments

@chvllad
Copy link

chvllad commented Jun 21, 2024

Hi. Thank you for library. I wonder is it possible to implement execute[Raw]Async and reactiveExecute for prepared statements and will it have any performance improvements?

@ospfranco
Copy link
Contributor

reactive queries already use prepared statements internally. execute is for one time operations, if you want prepared statements there is already APIs for that. Or am I misunderstanding you?

@chvllad
Copy link
Author

chvllad commented Jun 21, 2024

I wonder is it possible to use prepared statements in such fashion:

const statement = db.prepareStatement('SELECT * FROM User WHERE name = ?;');
// ...
const getData = statement.executeAsync(..);
const cancelUpdate = statement.reactiveExecute({ ... });

For example if pagination is used I call reactiveExecute each time page changes. And as far I understand it recreates statement from query each time. Is it possible to cache statement outside of reactiveExecute in this case?

@ospfranco
Copy link
Contributor

you don't need to do anything, reactiveExecute already uses a prepared statement internally.

@devontivona
Copy link

@ospfranco Understood that reactiveExecute uses prepared statements internally. For those not using reactive queries, is the addition of executeAsync to prepared statements on the roadmap?

Would like to be able to do:

const statement = db.prepareStatement('SELECT * FROM User WHERE name = ?;');
const statement.bind(params);
const getData = statement.executeAsync();

Thanks for your consideration!

@ospfranco
Copy link
Contributor

Prepared statements are already implemented. Read the docs.

@devontivona
Copy link

devontivona commented Sep 13, 2024

@ospfranco I understand that prepared statements are implemented, but it's my understanding that executeAsync is not implemented for prepared statements. Am I misunderstanding something?

@devontivona
Copy link

The prepared statement object appears to only have an execute function, not executeAsync:

image

@ospfranco
Copy link
Contributor

Ah, sorry. I misunderstood. Yeah, in the current stable version there is only the sync api. You can try the next beta version where there is only async execute.

#142

@devontivona
Copy link

Oh sweet—thanks! And thanks for the really quick response. Will try out the beta. Prepared statements really sped up my use-case (loading a ton of data), but blocked renders, so I swapped back. This is going to be huge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants