Composition of linked SQL files
Project description
sqlcompose: Composition of linked SQL files
sqlcompose allows you to compose sql files from multiple files by introducing INCLUDE keywords. The SQL output is composed as CTE's or Common Table Expressions.
Examples
Execute the script directly:
sqlcompose query.sql
sqlcompose 'select * from $INCLUDE(included-query1.sql)' # on linux
sqlcompose "select * from $INCLUDE(included-query1.sql)" # on windows
Import it in another script:
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.2.tar.gz.
File metadata
- Download URL: sqlcompose-0.0.2.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c880beabf671469f2280a6d8b39235f907654ce44c8950bef695d89b0dcb86fe
|
|
| MD5 |
d8805ff0b0f142e20f8d93a6135200c1
|
|
| BLAKE2b-256 |
f06378d402c8952ed9b34bcace90695df8a89d66aacd4891f7bc4c9ec40e54cd
|
Provenance
The following attestation bundles were made for sqlcompose-0.0.2.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.2.tar.gz -
Subject digest:
c880beabf671469f2280a6d8b39235f907654ce44c8950bef695d89b0dcb86fe - Sigstore transparency entry: 205912632
- Sigstore integration time:
-
Permalink:
apmadsen/sqlcompose@64ca0620001a8a66d4f55b32cddf06672de4729c -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/apmadsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@64ca0620001a8a66d4f55b32cddf06672de4729c -
Trigger Event:
release
-
Statement type:
File details
Details for the file sqlcompose-0.0.2-py3-none-any.whl.
File metadata
- Download URL: sqlcompose-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3a1adb26e8ec32ac52bb0ab60b602fe4f57d7cd2de23b853b0dd4cabbc9ca7
|
|
| MD5 |
37916aa34a30e624ee714c91b034b50e
|
|
| BLAKE2b-256 |
4e9aec81bce396aa732421e40011e53dab8aa022dccfb87bba5677fc31ac6822
|
Provenance
The following attestation bundles were made for sqlcompose-0.0.2-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.2-py3-none-any.whl -
Subject digest:
0a3a1adb26e8ec32ac52bb0ab60b602fe4f57d7cd2de23b853b0dd4cabbc9ca7 - Sigstore transparency entry: 205912635
- Sigstore integration time:
-
Permalink:
apmadsen/sqlcompose@64ca0620001a8a66d4f55b32cddf06672de4729c -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/apmadsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@64ca0620001a8a66d4f55b32cddf06672de4729c -
Trigger Event:
release
-
Statement type: