Skip to main content

SQL + Jinja Templates Done Right™

Project description

Overview

SQL + Jinja Done Right™

This project is a thing wrapper around Jinja templates to help manage the generation of SQL.

In your project create a directory name sql/templates to manage you SQL files:

.
└── sql
    └── templates
        ├── foo.sql
        └── bar.sql

An example foo.sql might be:

SELECT '{{msg}}' as message

Then to access the SQL template use the following Python snippet:

from sqlninja import engine as sqlninja

query = sqlninja.render("foo.sql", msg="Hello World")

The resulting query would be:

SELECT 'Hello World' as message

In bar.sql lets try including foo.sql:

SELECT * FROM ({% include 'foo.sql' %}) as t1

The rendered SQL would be:

SELECT * FROM (SELECT 'Hello World' as message) as t1

Command Line Interface

The Python interface makes sense at runtime, but for development the CLI is more convenient.

So see the resulting SQL we can try:

sql foo.sql msg='Hello World'

# => SELECT 'Hello World' as message

Installation

pip install sql-ninja

Or add to requirements.txt

sql-ninja

Or add to setup.py

setup(
    install_requires=[
        'sql-ninja',
    ]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ddrscott/sql-ninja

License

The gem is available as open source under the terms of the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sql-ninja-0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

sql_ninja-0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file sql-ninja-0.1.tar.gz.

File metadata

  • Download URL: sql-ninja-0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for sql-ninja-0.1.tar.gz
Algorithm Hash digest
SHA256 a0c97f474c378752b760552d905c80d1913b4e4e39a13ab3c02014e5161d7638
MD5 07802919105b0c4367757bb4fa2fe9c9
BLAKE2b-256 135ebd20a94d401627c1fdbf89be7505f3543425a09206f436172792e0c81a2e

See more details on using hashes here.

File details

Details for the file sql_ninja-0.1-py3-none-any.whl.

File metadata

  • Download URL: sql_ninja-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for sql_ninja-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d6de8e83ac18b24f89070deecca22bbffa736e6a10a319b3d24a0be7edbc8b1
MD5 c2c41c88bceb915523f61027da9adb00
BLAKE2b-256 de9ba500c4d54520dfc09d6fb649a34d0b0ad197483f95404cd34eafd83d1d89

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page