No project description provided
Project description
SQLecto
SQLecto is a command-line tool for converting SQL queries across different SQL dialects, providing flexibility for users working with SQL transformations. This tool leverages the powerful SQLGlot library for parsing and transpiling SQL queries.
Features
- Dialect Conversion: Transpile SQL queries from one SQL dialect to another (e.g., Spark to Snowflake)
- File Support: Process individual SQL/Python files or entire directories containing SQL code
- Configurable Mappings: Define custom table mappings and configurations via JSON or YAML files
Requirements
- Python 3.8+
Quck Start
Installation
You can install SQLecto via pipx
(recommended) or pip
.
Using pipx
pipx install sqlecto
Using pip
pip install sqlecto
Basic Usage
Convert a single SQL file:
sqlecto --source-dialect spark --target-dialect snowflake --source-files ./my_query.sql
Convert all SQL files in a directory
sqlecto --source-dialect spark --target-dialect snowflake --source-dir ./sql_scripts
Command Options
Option | Required | Description | Default |
---|---|---|---|
--source-files |
No | SQL/Python files to process | None |
--source-dir |
No | Directory containing SQL/Python files | Current directory |
--source-dialect |
Yes | Source SQL dialect | None |
--target-dialect |
Yes | Target SQL dialect | None |
--table-mappings |
No | Table name mappings | None |
--table-mappings-file |
No | File containing table mappings | None |
--config-file |
No | Configuration file path | None |
--output-dir |
No | Output directory for converted files | ./transpiled_queries |
Example Command
sqlecto --source-dialect spark --target-dialect snowflake \
--source-dir ./sql_scripts --output-dir ./transpiled_queries
Configuration
Configuration File Example
Configuration can be managed via JSON
or YAML
files, allowing reusable settings:
{
"source_files": ["./path/to/file.sql", "./path/to/file2.py"],
"source_dialect": "spark",
"target_dialect": "snowflake",
"output_dir": "./transpiled_queries",
"table_mappings": [{ "src_table": "old_table", "dst_table": "new_table" }]
}
Table Mappings
To replace table names within SQL queries, use --table-mappings
or specify mappings in a configuration file.
Mappings follow the format:
--table-mappings source_table:target_table
Or in JSON/YAML
:
"table_mappings": [
{"src_table": "old_table", "dst_table": "new_table"}
]
# mappings.yaml
table_mappings:
- src_table: old_table1
dst_table: new_table1
- src_table: old_table2
dst_table: new_table2
Examples
Basic Conversion
sqlecto --source-dialect spark --target-dialect snowflake \
--source-files ./query.sql --output-dir ./converted
Directory Processing with Table Mappings
sqlecto --source-dialect spark --target-dialect snowflake \
--source-dir ./sql_scripts \
--table-mappings old_db.table1:new_db.table1 \
--output-dir ./converted
Using Configuration File
sqlecto --config-file ./config.yaml
Credits
This tool heavily relies on the SQLGlot package by Toby Mao, providing robust and reliable SQL dialect transformations.
Contributing
Contributions are welcome! Please fork the repository and create a pull request for any improvements.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sqlecto-0.0.2.tar.gz
.
File metadata
- Download URL: sqlecto-0.0.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48479393f71b2448cd20a8004d6dcc2730d2c0f4b474b45a1d10c2327e6bbc34 |
|
MD5 | 56fe614ca1786e22e795950c2be99d3d |
|
BLAKE2b-256 | 5ad9ff2b77368debee5a7ccc870a077aea8116de416f83402e67c3b72e076f0b |
Provenance
The following attestation bundles were made for sqlecto-0.0.2.tar.gz
:
Publisher:
release.yaml
on valdAsync/sqlecto
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
sqlecto-0.0.2.tar.gz
- Subject digest:
48479393f71b2448cd20a8004d6dcc2730d2c0f4b474b45a1d10c2327e6bbc34
- Sigstore transparency entry: 149356193
- Sigstore integration time:
- Predicate type:
File details
Details for the file sqlecto-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: sqlecto-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec6cea776c25d079af2a4783ea0d2adb87fdbf2c87e2245db33aa0cf87d45f9c |
|
MD5 | 5ce2c0120ebef0d2cc5cde8b4d2eaacd |
|
BLAKE2b-256 | c767a9d4dcd2b112b9f8f0ac8fb5ba829cccddae2a068a73f762da925adf9cfc |
Provenance
The following attestation bundles were made for sqlecto-0.0.2-py3-none-any.whl
:
Publisher:
release.yaml
on valdAsync/sqlecto
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
sqlecto-0.0.2-py3-none-any.whl
- Subject digest:
ec6cea776c25d079af2a4783ea0d2adb87fdbf2c87e2245db33aa0cf87d45f9c
- Sigstore transparency entry: 149356195
- Sigstore integration time:
- Predicate type: