Python Wrapper for use in recording the success or failure of any functions to a SQL table, along with any respective arguments or keyword arguments
Project description
SQLRecorder
This package serves as a Python Wrapper for use in recording the success or failure of any functions to a SQL table, along with any respective arguments or keyword arguments.
As of 2021-05-31 this package has only been tested with Microsoft SQL Server utilising pyodbc with SQL Server Native Client 11.0 and windows authentication (trusted_connection=yes).
Instructions
Install the package using pip install sqlrecorder
In your application, from sqlrecorder import SQLRecorderWrapper
Set up your config variables:
# instantiate SQLoggerOne as a copy of SQLRecorderWrapper so multiple configs are possible for the one application
SQLoggerOne = SQLRecorderWrapper
# what to do in the event the wrapped function throws an error
SQLoggerOne.config['ON_FAIL'] = 'pass'
# connection string
SQLoggerOne.config['CONNECTION_STRING'] = 'mssql+pyodbc://@DESKTOP-8TLT5OK\\SQLEXPRESS/Test?driver=SQL+Server+Native+Client+11.0?trusted_connection=yes'
# table name which the logs are written to
SQLoggerOne.config['TABLE_NAME'] = 'py_errorlog'
Config:
ON_FAIL
str: 'pass', passes when the wrapped function throws an error
str: 'return', returns the function and associated args and kwargs when the wrapped function throws an error
str: 'exit', returns sys.exit when the wrapped function throws an error
CONNECTION_STRING
str The connection string used to connect with the database instance. See: SQL Alchemy documentation
TABLE_NAME
str The table name to be created in SQL.
Sample Success
from sqlrecorder import SQLRecorderWrapper
SQLoggerOne = SQLRecorderWrapper
SQLoggerOne.config['ON_FAIL'] = 'pass'
SQLoggerOne.config['CONNECTION_STRING'] = 'mssql+pyodbc://srvr/db?driver=driver?trusted_connection=yes'
SQLoggerOne.config['TABLE_NAME'] = 'py_func_log'
@SQLoggerOne
def add_func(a,b):
return a+b
add_func(2, 2)
Which will send to SQL:
Sample Errors
Assuming the above code but with the following two calls of add_func
add_func(2, 2, 3) # invalid, third argument
add_func(2, 2, invalid_kwarg=1) # invalid keyword argument
Would update the existing table to:
TODO:
- Return NULL/None when len(kwargs) == 0
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlrecorder-1.0.tar.gz.
File metadata
- Download URL: sqlrecorder-1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fa748213e00e7e63adbcaeedd2618934fa9e8480de4dfb6c6097b32fcad5f4a
|
|
| MD5 |
b83c7bb000e9a92aab0d38977e85447a
|
|
| BLAKE2b-256 |
3499e3f5acdbd18243eae55e0492889b7067827e4e958afa2f0ee61bc6e69317
|
File details
Details for the file sqlrecorder-1.0-py3-none-any.whl.
File metadata
- Download URL: sqlrecorder-1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc0b1f3be1450afb348e8e0e5dd6b5720da5171d61ea88b41a530d9af1adeb8a
|
|
| MD5 |
4904e9a41d2ac4953a652baa85ecabd8
|
|
| BLAKE2b-256 |
76886b8db71ef75dc149c50f3c28c934619bb2060f194c89eb9ec8eab9bb9268
|