Skip to main content

Aid writing boilerplate SQL items from create tables, inserts and updates.

Project description

devtools_shorthand_sql

image image image Travis readthedocs

Overview

Aid for writing boilerplate python code for SQL work, including creation of tables, insert functions, unit testing and SQL, dependent on relational database management system selected.

Features

  • TODO

Requirements

You need Python 3.6 or later to run devtools_shorthand_sql.

No other third party packages are required.

Quickstart

Install the latest version of this software from the Python package index (PyPI):

pip install --upgrade devtools_shorthand_sql

Create a shorthand sql file e.g. shorthand.txt.

# table photo
size int
filename text
date_taken int

Run

devtools_shorthand_sql shorthand.txt

SQL statement for table creation:

CREATE TABLE IF NOT EXISTS photo (
id INTEGER PRIMARY KEY,
size int,
filename text,
date_taken int
);

Python function for data insertion:

def insert_photo(size: int, filename: str, date_taken: int) -> int:
    params = (None, size, filename, date_taken)
    id = YOUR_CONNECTOR_EXECUTOR("""INSERT INTO photo (id, size, filename, date_taken) VALUES(?,?,?,?);""",
                                 params)
    return id

Python function for unit testing:

def test_insert_photo(YOUR_CLEAN_DB_FIXTURE):
    expected = (1, 999, '123fakestreet', 999)
    YOUR_MODULE.insert_photo(size=999, filename="123fakestreet", date_taken=999)
    result = YOUR_CONNECTOR_QUERY('SELECT * FROM photo').fetchall()[0]
    assert result == expected

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

devtools_shorthand_sql-0.3.0.tar.gz (10.9 kB view hashes)

Uploaded Source

Built Distribution

devtools_shorthand_sql-0.3.0-py2.py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 2 Python 3

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