preprocesses SQL queries to make them modular
Project description
querypp
querypp preprocesses SQL queries[1] in order to "parameterize" them. It also includes a loader which loads many queries
from a file, delimited by -- :name query_name
lines.
[1] Although it is trivially adapted to other languages with line comments, as the only SQL-specific assumption is the comment syntax.
Take an example:
SELECT *
FROM users
-- :param profiles
LEFT JOIN profiles USING (user_id)
-- :param login_history
LEFT JOIN login_history USING (profile_id)
-- :endparam
-- :endparam
-- :param user_id WHERE user_id = $1
A Query object can be called:
- with no parameters to return the entire query
- with one or more parameters to return the query with only those parameters.
In this case, q('profiles', 'user_id')
would return the query with the login_history
JOIN removed.
Motivation
After moving all my SQL queries to separate files (using the load_sql function), I noticed that I was duplicating some of them except for one extra clause. I created this to allow me to deduplicate such queries.
License
Public domain, see COPYING
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
Hashes for querypp-0.0.2.post3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9f58dd3ec0f501ea8770d49fb65b2d73a85555dfce163f15e65d1e76af8dca8 |
|
MD5 | 17efc49c36d6cf2da96e7f740748e7fd |
|
BLAKE2b-256 | 9ab46a541a3c777f868b3c728fb906f6a3e8e3473b0237175f5879a8040251d6 |