Metadata-Version: 2.1
Name: querypp
Version: 0.1.2
Summary: SQL query templating shorthand
Home-page: https://github.com/bmintz/querypp
Author: Benjamin Mintz
Author-email: bmintz@protonmail.com
License: CC0 1.0
Platform: UNKNOWN
Classifier: Topic :: Software Development
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Description-Content-Type: text/markdown
Requires-Dist: jinja2 (<3.0.0,>=2.10.1)

# querypp

## Deprecation Notice

querypp has been deprecated in favor of vanilla jinja2. After porting it to jinja2, I realized that none of querypp
was actually necessary. [Migrating docs here](https://github.com/iomintz/querypp/blob/master/MIGRATING.md).

[v0.0.3](https://github.com/iomintz/querypp/tree/v0.0.3) is the last version that doesn't use jinja2, in case
you want a more lightweight version.

-------------------------------------------------------------------------------------------------------------

querypp is a SQL query[1] templating system based on [jinja2](https://palletsprojects.com/p/jinja/).

[1]: Although it is trivially adapted to other languages, as the only SQL-specific assumption is the line comment
syntax.

Take an example:

```
-- :query users
SELECT *
FROM users
-- :qblock profiles
	LEFT JOIN profiles USING (user_id)
	-- :block login_history
		LEFT JOIN login_history USING (profile_id)
	-- :endqblock
-- :endqblock
-- :qblock user_id WHERE user_id = $1
-- :endquery
```

A Query template can be called:
  - with no block names to return the query without any blocks
  - with one or more block names to return the query with only those block names.

In this case, `q('profiles', 'user_id')` would return the query with the `login_history` JOIN removed.

Additionally, any [jinja2 templating features](https://jinja.readthedocs.io/en/2.10.x/templates/),
such as variables and macro functions, can be used, using either the line syntax (e.g. `-- :include 'foo.sql'`)
or the block syntax (e.g. `{% if x == 1 %}`).

## Usage

```
env = querypp.QueryEnvironment('sql/')
queries = env.get_template('queries.sql')  # opens sql/queries.sql
db.execute(queries.users('login_history', 'user_id'), user_id)
```

## Motivation

After moving all my SQL queries to separate files,
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](https://github.com/bmintz/querypp/blob/master/COPYING)


