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 Scala version of the Table Trace project written in Rust.
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.git
cd table-trace- JDK 11+
- SBT 1.8+
- Scala 2.13
You can run the Table Trace api directly from SBT. Open a terminal in the project directory and execute:
sbt run-apiBy 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)"
}'{
"tables": [
"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 processing the query `UPDATE wine w WHERE w.name IN (SELECT order.wine_name FROM order WHERE date = CURRENT_DATE)`
Prepare your project for distribution or deployment by building it with SBT:
- Navigate to the project directory:
cd table-trace- Run the assembly:
sbt clean api/assembly
This command creates a JAR file in the api/target/scala-2.13/ directory. For more details on configuring *
sbt-assembly*, refer to the sbt-assembly documentation.
Once the JAR is built, you can run the API directly with:
java -jar api/target/scala-2.13/table-trace-api-0.0.1.jarBy 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.