TableTrace is a lightweight HTTP API that extracts the table names involved in a given SQL query. It supports parsing queries and returning a JSON list of table names. This is a Rust version of the Table Trace project written in Scala.
Follow these steps to set up and run your Table Trace api:
First, clone this repository to your local machine:
git clone git@github.com:rafafrdz/table-trace-rs.git
cd table-trace-rs- Rust 1.89+
- Cargo
You can run the Table Trace api directly from Cargo. Open a terminal in the project directory and execute:
cargo runBy default, the service runs on http://localhost:9876
POST /analyze
Body: JSON with the field query containing the SQL string.
Response: JSON array with the extracted tables.
curl -X POST http://localhost:9876/analyze -H "Content-Type: application/json" -d '{
"query": "UPDATE wine w SET stock = stock - (SELECT SUM(quantity) FROM order WHERE date = CURRENT_DATE AND order.wine_name = w.name) WHERE w.name IN (SELECT order.wine_name FROM order WHERE date = CURRENT_DATE)"
}' [
"wine",
"order"
]
curl -X POST http://localhost:9876/analyze -H "Content-Type: application/json" -d '{
"query": "UPDATE wine w WHERE w.name IN (SELECT order.wine_name FROM order WHERE date = CURRENT_DATE)"
}'{
"error": "Error processing the query `UPDATE wine w WHERE w.name IN (SELECT order.wine_name FROM order WHERE date = CURRENT_DATE)`. Validation error: sql parser error: Expected: SET, found: WHERE at Line: 1, Column: 15"
}Prepare your project for distribution or deployment by building it with Cargo:
- Navigate to the project directory:
cd table-trace-rs- Run the following command:
cargo build --releaseThis command creates a binary in target/release/table-trace-rs. For more details of this command, refer to the cargo-build documentation.
Once the binary is built, you can run the API directly with:
./target/release/table-trace-rsBy default, the service runs on http://localhost:9876
This project is available under your choice of the Apache 2.0 or CC0 1.0 license. Choose the one that best suits your needs:
This template is provided "as-is" without any warranties. Modify and distribute as needed to fit your project requirements.