Composition of SQL files
Project description
sqlcompose: Composition of SQL files
sqlcompose lets you to compose sql files from multiple files by introducing $INCLUDE keywords. The SQL output is composed as CTE's or Common Table Expressions.
Using composition, you reduce both complexity and duplication of code thus adhering to the DRY principle.
SQL Dialect
sqlcompose outputs SQL as standard ANSI SQL. Note though, that no validation is done on either the input or the output.
Examples
1. Execute the script with the filename as an argument and output to the console:
sqlcompose query.sql
2. Pipe data into application and output to a file
cat query.sql | sqlcompose > output.sql
3. Execute the script with SQL string as argument
sqlcompose 'select * from $INCLUDE(included-query1.sql)'
NOTE: Different consoles have different limitations, so you may have to switch from single to double quotes to allow for using the dollar sign.
4. Import it in another python application or package
from sqlcompose import load, loads
# method 1 : loading from a file
sql1 = load("query.sql")
# method 2 : loading from an SQL string
sql2 = loads("""
select *
from dataset.table main
inner join $INCLUDE(other.sql) other
on other.field = main.field
""")
Preparing SQL scripts
Insert a $INCLUDE(filename) where the reference to the file should be in the resulting SQL, keeping in mind that references are loaded relative to the file loaded or the current working dir in case of an SQL string.
--main-query.sql
select * from $INCLUDE(includes\included-query2.sql)
--included-query1.sql
select 1 as test
--included-query2.sql
select * from $INCLUDE(included-query1.sql)
union all
select * from $INCLUDE(nested\included-query3.sql)
--nested\included-query3.sql
select 1 as test
Which outputs:
WITH Q_1_1 AS (
WITH Q_2_1 AS (
--includes\included-query1.sql
select 1 as test
), Q_2_2 AS (
--includes\nested\included-query3.sql
select 1 as test
), Q_2 AS (
--includes\included-query2.sql
select * from Q_2_1
union all
select * from Q_2_2
)
SELECT * FROM Q_2
), Q_1 AS (
--test\main-query.sql
select * from Q_1_1
)
SELECT * FROM Q_1
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlcompose-0.0.4a2.tar.gz.
File metadata
- Download URL: sqlcompose-0.0.4a2.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a93512179d532d7240412ae6e5a19702d10aa0318ba31a080df016f6a4671735
|
|
| MD5 |
5c7e5730023b187acf22fb812f3601ae
|
|
| BLAKE2b-256 |
4078fcf2a6dcb94533022f7a6a33bb6967692f893bcb833d8ca9a10caabb63fe
|
Provenance
The following attestation bundles were made for sqlcompose-0.0.4a2.tar.gz:
Publisher:
python-publish.yml on apmadsen/sqlcompose
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlcompose-0.0.4a2.tar.gz -
Subject digest:
a93512179d532d7240412ae6e5a19702d10aa0318ba31a080df016f6a4671735 - Sigstore transparency entry: 1295785985
- Sigstore integration time:
-
Permalink:
apmadsen/sqlcompose@909177fc4eaeabb7c60287689d8ece0960fdd975 -
Branch / Tag:
refs/tags/v0.0.4a2 - Owner: https://github.com/apmadsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@909177fc4eaeabb7c60287689d8ece0960fdd975 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sqlcompose-0.0.4a2-py3-none-any.whl.
File metadata
- Download URL: sqlcompose-0.0.4a2-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
330932d20f72f380a86748e7ffa163a30a757c3b1c5b9f9215ec4eb9f2ac4d4e
|
|
| MD5 |
c43640a8e3eb1dff9de54981bd14020d
|
|
| BLAKE2b-256 |
f4cab5a18dc856e29abf71c691c03a579bafee68f502216366fcf8879fa1abf0
|
Provenance
The following attestation bundles were made for sqlcompose-0.0.4a2-py3-none-any.whl:
Publisher:
python-publish.yml on apmadsen/sqlcompose
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlcompose-0.0.4a2-py3-none-any.whl -
Subject digest:
330932d20f72f380a86748e7ffa163a30a757c3b1c5b9f9215ec4eb9f2ac4d4e - Sigstore transparency entry: 1295786126
- Sigstore integration time:
-
Permalink:
apmadsen/sqlcompose@909177fc4eaeabb7c60287689d8ece0960fdd975 -
Branch / Tag:
refs/tags/v0.0.4a2 - Owner: https://github.com/apmadsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@909177fc4eaeabb7c60287689d8ece0960fdd975 -
Trigger Event:
release
-
Statement type: