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

db.mysql: Add the exec family of methods #19132

Merged
merged 7 commits into from
Aug 14, 2023

Conversation

jacksonmowry
Copy link
Contributor

@jacksonmowry jacksonmowry commented Aug 13, 2023

As discussed in: #19098

This change adds exec, exec_one, exec_none, exec_param_many, and exec_param to db.mysql. These methods serve as simple abstractions on top of db.mysql returning values that the user can directly interact with.

The purpose is to get a more consistent API across all of the db modules, which should allow the user to transition between databases with little change needed to the code (outside of setting up and closing a connection).

Each method (excluding exec_none) with either return row(s) or an error, which is consistent with other db modules. Rows are arrays of strings, representing each column in order.

🤖 Generated by Copilot at 6655507

This pull request adds support for parameterized queries in the mysql module. It implements new methods for the DB struct that use the C MySQL API to execute and fetch queries with or without parameters. It also adds a test function to the mysql_test.v file that checks the correctness and consistency of the new methods.

🤖 Generated by Copilot at 6655507

  • Add new methods to DB struct for executing parameterized queries and returning different types of results (link)
  • Add test function to mysql_test.v that creates a temporary table, inserts data, and executes various queries using the new methods, asserting correctness and consistency (link)

vlib/db/mysql/mysql.v Outdated Show resolved Hide resolved
@jacksonmowry
Copy link
Contributor Author

I guess I just need some help setting up the MySQL connection in the new test file. I tried to copy what was in the ORM test but I guess that didn't work.

@spytheman
Copy link
Member

I tried to copy what was in the ORM test but I guess that didn't work.

Sorry, it is a deficiency in our current testing/CI setup, since we do not start external services like PostgreSQL or MySQL, the corresponding tests are skipped and not run.

They can be run locally with: v vlib/db/mysql/mysql_orm_test.v etc, as long as there is a local database service running, but that is done manually and much less frequently than on each commit, which is not great since it can lead to regressions, like what has happened to mysql_orm_test.v .

@spytheman
Copy link
Member

I'll think about a better setup, so that all the DB tests including the PostgreSQL and MySQL ones, are run on the CI, in at least one job.

@spytheman spytheman merged commit d285ff0 into vlang:master Aug 14, 2023
41 checks passed
@jacksonmowry
Copy link
Contributor Author

Thank you for the review and collaboration @spytheman

Wertzui123 pushed a commit to Wertzui123/v that referenced this pull request Oct 8, 2023
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

Successfully merging this pull request may close these issues.

2 participants