ppsql
ppsql is a preprocessor for SQL files. It expands variables, inlines included files
and strips comments before the result is handed over to a database client.
Table of Contents
Installation
pip install ppsql
Usage
ppsql -i path/to/main.sql -o path/to/out.sql
| Option | Description | Default |
|---|---|---|
-i, --input |
entry point of the build (required) | - |
-s, --source |
source directory | current dir |
-o, --out |
output file | ./out.sql |
-e, --env |
file or directory holding a .env file |
current dir |
-c, --credential |
directory holding a .password file |
home dir |
-d, --debug |
verbose logging | off |
The module can also be executed directly:
python -m ppsql -i path/to/main.sql -o path/to/out.sql
Directives
Every directive is written on its own line and is removed from the output.
| Directive | Description |
|---|---|
@set name = value |
sets a variable in the scope of the file |
@set global name = v |
sets a variable in the global scope |
@unset name = |
removes a variable |
@include path |
inlines a file, or index.sql of a directory |
A variable is referenced as $name or, when the name touches other characters,
as ${name}. Write \$name to keep a dollar sign as it is. Values are looked up in
the scope of the file, then in the global scope, which is initialised from the
environment and extended by --env and --credential files.
@set table = users
@include queries/columns.sql
select * from ${table};
$ ppsql -i main.sql -o out.sql && cat out.sql
select id, name from users;
select * from users;
Python API
from ppsql import Builder
sql = Builder(entry="main.sql", variables={"table": "users"}).build()
| Object | Responsibility |
|---|---|
Builder |
builds an entry point, resolves includes |
Context / Line |
the content of a file and a cursor over it |
VariableScope |
local and global variables |
Loader |
reads a file and creates a Context |
Writer |
writes the result into a file |
actions |
the directive handlers and the Action protocol |
cli |
argument reader, load_env, load_password |
Development
The project is managed by hatch:
hatch run test # run the test suite
hatch run test-cov # run the test suite with coverage
hatch run lint:check # check formatting and lint rules
hatch run lint:fix # fix formatting and lint rules
hatch run types:check # run mypy
hatch build # build the sdist and the wheel
License
ppsql is distributed under the terms of the MIT license.
Metadata
Release files for ppsql 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ppsql-0.1.0.tar.gz | 15.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ppsql-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.4 kB
Release files / ppsql-0.1.0.tar.gz
| Download URL | ppsql-0.1.0.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b4a0072418411597d83ecd6f30872101530073f7666f36586867606c62655d3
|
|
BLAKE2b-256 checksum How to use checksums |
54415d84951d7dd07a74f07a6b179ce0ff0f5a70b774fdde592e9a25ed57ac83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.3 cpython/3.14.0 HTTPX/0.28.1
|
Release files / ppsql-0.1.0-py3-none-any.whl
| Download URL | ppsql-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc3b6890f12459e06d10a9e6ca1b9335555b7e5528393947e7d50eee5208c1f5
|
|
BLAKE2b-256 checksum How to use checksums |
c333fe300f33a7d2697c8b306810725a080bc30d976c9c73372f211088d8f58a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.3 cpython/3.14.0 HTTPX/0.28.1
|