Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

allure_db_client-1.2.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

allure_db_client-1.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file allure_db_client-1.2.0.tar.gz.

File metadata

  • Download URL: allure_db_client-1.2.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Darwin/23.5.0

File hashes

Hashes for allure_db_client-1.2.0.tar.gz
Algorithm Hash digest
SHA256 c4291b948bf8631017c8a5212efb0805a4bed4b324938a5901687e11e2e9338d
MD5 5a2091905b4a3216cb93dedf8c55ed1b
BLAKE2b-256 400325e11098af66f40fede8f8e5406186c8e97c8e0fefbc6f495d7551adfea6

See more details on using hashes here.

File details

Details for the file allure_db_client-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for allure_db_client-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 245af2701c59f5291ef7cd10bdfd092b91fd47f42dcab49dd9c274f20250a481
MD5 8649230c979c25a97507f659e0d8b27f
BLAKE2b-256 7f23b57e9f4b05f00d702ea3593e26f824aff3b8bba1a2f23d9289aba6bd40e0

See more details on using hashes here.

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