A tiny library for submitting raw SQL via SQLAlchemy
Project description
sqla-raw
I've copy-pasted this enough times that it seemed worth packaging. Really not much more than a single method (raw.db.result
) to submit SQL to a database using a SQLAlchemy engine connection, and get results as a list of dictionaries, with each dict keyed by result set column names.
Installation
pipenv install sqla-raw[pg]
Usage
Configure your database connection string by setting $DATABASE_URL
in your environment.
>>> from raw import db
>>> x = db.result('select version()');
>>> x
[{'version': 'PostgreSQL 10.10 on x86_64-apple-darwin14.5.0, compiled by Apple LLVM version 7.0.0 (clang-700.1.76), 64-bit'}]
Because it's SQLAlchemy, you can use named parameters in your SQL string with colon-prepended :key
format, and assign values in kwargs
.
Also, by setting optional parameter jinja=True
, you can use Jinja2 templating syntax to interpolate the query, if desired. (It uses a SandboxedEnvironment
, but avoid this option with untrusted inputs, for obvious reasons.)
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 sqla_raw-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ee2da020b984d1ec761676e2d9d0ac5c804fbccf7ef45a86a39305f9d8d1f32 |
|
MD5 | b9f22b66113e1d0d9f5130b94d8cd0d5 |
|
BLAKE2b-256 | 9686079e0d2460dc98904bffaa749aad0ae14aff0672fc3783803c44200926bd |