query_craft is a CLI tool designed to convert a list of user IDs stored in a CSV file into a SQL query, facilitating quick and error-free generation of SQL statements for database operations.
- Read User IDs from CSV: Takes a CSV file as input and reads list of user IDs.
- Generate SQL Statements: Based on user inputs, generates SQL queries (
SELECT,UPDATE, orDELETE). - Interactive CLI: Interactive prompts to customize the SQL query based on user needs.
- Error Handling: Gracefully handles file read errors and user input errors.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Go (Golang) - Make sure you have Go installed on your system
First, clone the repository to your local machine:
git clone https://github.com/o8n/query_craft.git
cd query_craftNext, build the project using:
go build -o query_craftNow, you can run the tool using:
./query_craft path/to/your/file.csvTo use query_craft, you need a CSV file with user IDs listed, one per line. Here’s how you can run the tool:
./query_craft sample.csvYou will be prompted with a series of questions:
- Do you want to generate a SQL statement? [yes/no] - Answer
yesto proceed. - Please choose: SELECT, UPDATE, or DELETE - Choose the type of SQL operation you need.
- Enter the table name: - Specify the table to query against.
- If you choose
UPDATE, you will also be asked to Enter the set clause (e.g.,set column = value):.
Given a sample.csv file with the following content:
111
222
333
Running ./query_craft sample.csv and choosing to generate a SELECT statement for the users table, you might see:
Do you want to generate a SQL statement? [yes/no]
yes
Please choose: SELECT, UPDATE, or DELETE
SELECT
Enter the table name:
users
Generated SQL: SELECT * FROM users WHERE user_id IN (111, 222, 333);