DBClient that includes allure decorator that logging your queries and query results
Project description
allure-db-client
The allure-db-client is a Python library designed to facilitate the interaction with PostgreSQL databases. It leverages the psycopg library for database connectivity and integrates with the Allure framework for enhanced logging and debugging capabilities. This library simplifies executing SQL queries and retrieving results in various formats, making it particularly useful in testing and debugging environments.
Features
- Easy connection to PostgreSQL databases using a connection string.
- Methods to fetch query results as lists, dictionaries, or individual values.
- Integration with Allure for logging SQL queries and results.
- Context management for automatic opening and closing of database connections.
- Safe parameter substitution in SQL queries to prevent SQL injection.
Installation
To install allure-db-client, you will need to have Python installed on your system. The library can be installed using pip:
pip install allure-db-client
Usage
Creating a Client Instance
First, import DBClient from allure-db-client and create an instance with your database connection string:
from allure_db_client import DBClient
db_client = DBClient(connection_string="your_connection_string")
Executing Queries
You can execute various types of SQL queries using the provided methods:
get_list(query, params): Fetches the first column of each row as a list.get_dict(query, params): Fetches the first two columns of each row as a dictionary.select_all(query, params): Executes a query and fetches all rows.get_first_value(query, params): Fetches the first column of the first row.get_first_row(query, params): Fetches the first row.execute(query, params): Executes a non-returning SQL command (e.g., INSERT, UPDATE).
Context Management
The DBClient can be used as a context manager to automatically handle database connections:
with DBClient(connection_string="your_connection_string") as db_client:
# Your database operations here
Examples
Here's an example of using DBClient to fetch user data from a users table:
with DBClient(connection_string="your_connection_string") as db_client:
users = db_client.select_all("SELECT * FROM users")
for user in users:
print(user)
Contributing
Contributions to allure-db-client are welcome! Please read our contributing guidelines for details on how to submit pull requests, report issues, or request features.
License
allure-db-client is released under the MIT License. See the LICENSE file for more details.
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 allure_db_client-1.4.1.tar.gz.
File metadata
- Download URL: allure_db_client-1.4.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84ea49506b8132ca879117156396bdf6679f7a9ed9bb573cfbf203c13e8f5f91
|
|
| MD5 |
48ff34a6721b47126653ce0494832f32
|
|
| BLAKE2b-256 |
2e616f083d5b76dd51f4080a7c97bb5a015129deeddcc87e2df296e6382bcc3a
|
File details
Details for the file allure_db_client-1.4.1-py2.py3-none-any.whl.
File metadata
- Download URL: allure_db_client-1.4.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e68a80d448f3c8bfd1ba2fc0b49e724f65912def557baccfae4de28e0770b4a
|
|
| MD5 |
9ce85bfd9ac1c0ba008c57d1b19e4c91
|
|
| BLAKE2b-256 |
dfb7abfa1d46b0443dd884554e8268e341692debc0122a2667e90223e133bdd2
|