vanna-ai / vanna

🤖 Chat with your SQL database 📊. Accurate Text-to-SQL Generation via LLMs using RAG 🔄.
https://vanna.ai/docs/
MIT License
12.06k stars 966 forks source link

Add Autocommit Option to connect_to_mysql for Accurate Database Query Results #699

Open arthurmf opened 1 week ago

arthurmf commented 1 week ago

This pull request adds an autocommit parameter to the connect_to_mysql method, enabling users to toggle autocommit mode on MySQL connections. By setting autocommit=True, users can ensure the latest data changes in the database are reflected in their queries, solving an issue where cached results would appear even after data modifications.

Background

Some users have reported that query results returned by the Vanna application do not update immediately after data changes in the database. This is due to the default transaction behavior of MySQL when autocommit is set to False, which can lead to reading shadowed copies of data. The addition of the autocommit parameter provides a way to address this issue, allowing more accurate and timely data retrieval.

Changes Made

Usage

Users can enable autocommit mode by calling:

connect_to_mysql(host='localhost', user='user', password='password', dbname='db', autocommit=True)

Enabling autocommit ensures that the database fetches the most up-to-date records, improving the reliability and consistency of query results within the Vanna application.