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

get result from db.exec #847

Open
mccoysc opened this issue Jul 17, 2022 · 3 comments
Open

get result from db.exec #847

mccoysc opened this issue Jul 17, 2022 · 3 comments

Comments

@mccoysc
Copy link

mccoysc commented Jul 17, 2022

some time,we need run multiline sql and get the execute result,but now the api "exec" return no execute result

@mccoysc mccoysc changed the title get result from db.run get result from db.exec Jul 17, 2022
@JoshuaWise
Copy link
Member

JoshuaWise commented Jul 18, 2022

The goal of db.exec() is to be an easy-to-use function for executing large SQL scripts, typically stored in files (for example, database migrations). In such cases, the query results are generally not needed.

There are many problems with adding query results to db.exec(). For one, since there can be multiple statements, it's not easy to know which results are actually desired. Second, there are different types of results a user might be interested in (for example, prepared statements have four different methods, each for getting different types of results: run, get, all, and iterate), plus various methods for deciding the output format (pluck, expand, raw).

Because of these complications, the API for db.exec() would need to be quite complicated to support all use-cases. For this reason, it's purposefully dumb, and users are encouraged to use prepared statements for most tasks.

@mccoysc
Copy link
Author

mccoysc commented Jul 18, 2022

maybe it can return the last execute result as the final result.
some time,the sql is from other people and i can't get only 'one' sql.

@JoshuaWise
Copy link
Member

Perhaps there could be a function like db.parse(), which could take a multi-statement SQL string and return an array of prepared statement objects. That way, the user would still have complete control over how each statement gets executed, and which results they are interested in.

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

No branches or pull requests

2 participants