Aid writing boilerplate SQL items from create tables, inserts and updates.
Project description
devtools_shorthand_sql
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.
- Documentation: https://devtools-shorthand-sql.readthedocs.io.
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.
# photo
id,id
size,int
filename,text
date_taken,int
Run
devtools_shorthand_sql shorthand.txt
Notification that file created:
Info: Output saved to: shorthand_sql_created_functions.txt
Created file contains:
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(id: int, size: int, filename: str, date_taken: int) -> int:
params = (id, 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 (pytest only):
def test_insert_photo(YOUR_CLEAN_DB_FIXTURE):
expected = (1, 160, '3RWL0C6QSU', 374)
new_id = YOUR_MODULE.insert_photo(size=160, filename="3RWL0C6QSU", date_taken=374)
result = YOUR_CONNECTOR_QUERY('SELECT * FROM photo').fetchall()[0]
assert result == expected
assert new_id == 1
Requirements
Python 3.6 or later is required to run devtools_shorthand_sql.
No other third party packages are required.
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
Built Distribution
File details
Details for the file devtools_shorthand_sql-0.4.0.tar.gz
.
File metadata
- Download URL: devtools_shorthand_sql-0.4.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b51f71aa08c2a31c6190cc30ec34a205ed1029964cfc9f123cec3131e2c9a7e8 |
|
MD5 | e7171acae987a8ba89bbdce6d7993f76 |
|
BLAKE2b-256 | 7751d42027fe61c536274b382ef8495c7356de34794d8b1026254c7afcce181e |
File details
Details for the file devtools_shorthand_sql-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: devtools_shorthand_sql-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e44c60fd45b8c872912796c32c7d43dee818de867427a201976988e99d6bce2 |
|
MD5 | 74385a6d64275cc15fd2bd71a645c88d |
|
BLAKE2b-256 | 6109baa9cc5b67daa074c91e26374542b98e6084b67ae18eab37655576c69003 |