Note
This is the WinForms version meant for client use. There is a REST API version meant for servers and client use by Swagger interface.
This WinForms program uses Google's AI 'Gemini 1.5 Flash' to make queries to PostgreSQL databases.
The AI interprets natural language into SQL queries using one method, with its pros and cons.
To make this program work, you'll need a PostgreSQL Server and a Gemini API Key.
Note
I'll use pgAdmin to build the PostgreSQL Server.
If you don't have it, download pgAdmin 4 from the official website.
Now, create the PostgreSQL Server and set up a database with a few tables and insert values.
Next, obtain your Gemini API Key by visiting Google AI Studio. Ensure you're logged into your Google account, then press the blue button that says 'Create API key' and follow the steps to set up your Google Cloud Project and retrieve your API key. Make sure to save it in a safe place.
Google allows free use of this API without adding billing information, but there are some limitations.
In Google AI Studio, you can monitor the AI's usage by clicking 'View usage data' in the 'Plan' column where your projects are displayed. I recommend monitoring the 'Quota and system limits' tab and sorting by 'actual usage percentage,' as it provides the most detailed information.
You now have everything needed to make the program work.
Simply put that data you just got into the setting windows in the program.
The interface have a few buttons, being and
setting windows, for configuring the API Key and the database respectively and
/
to show or hide the AI's generated query.
The button displays a Mapped Databases Manager, where you can Map into JSON any database you want and select one for future requests to the AI.
These Mapped Databases are stored in your drive so they'll be always loaded when you start the program.
Remember that the Mapped Databases are only used in the AI requests, so when you run a tweaked query, it will run on the configured PostgreSQL Server instead.
When you click 'Save' in the Database Settings Window or in the API Key Settings Window (if the 'Remember' box is checked) a file will be created in the internal folder of the program so the next time the program is started, all this data gets loaded automaticly.
Note
The API Key and DB data configuration files are encrypted using AES with a Specific System Based Method, where the AES Key is made with your system's specs, so if any unwanted person steals those files, they couldn't be decrypted, maintaining your sensitive data secure.
Natural Language to SQL Translation Method:
This method maps the database structure into a JSON that Gemini analyzes to create an SQL query, which is then run by the PostgreSQL Server, returning the requested data.
Since this method does not map the database values, token usage is lower, and the data is more reliable because it comes directly from the PostgreSQL Server. However, it doesn't completely prevent AI-generated errors. Occasionally, the SQL query might fail due to non-existing columns, in which case you should check the generated query to detect the error.
The version will be released using these versioning policies:
New major features and critical bug fixes will cause the immediate release of a new version, while other minor changes/fixes will wait one week from the time the change is introduced in the repository before being included in the new version, so that other potential changes can be added.
Note
These potencial new changes will not increase the wait time for the new version beyond one week.
The version number will follow this format:
[Major Feature].[Minor Feature].[Bug Fixes]
- Programming Language: C#
- Framework: .Net 8.0 Framework
- NuGet Packages:
- Npgsql (8.0.5)
- RestSharp (112.1.0)
- Newtonsoft.Json (13.0.3)
- System.Management (9.0.1)
- Other:
- PostgreSQL (16.3)
- pgAdmin 4 (8.9)
- Gemini API Key (1.5 Flash)
- Images (Icons source, later retouched by me):
- Microsoft Visual Studio Installer Projects 2022 (2.0.1)
- Recommended IDE: Visual Studio 2022