Skip to main content

Database Query and Backup Script - Summary

This script provides the get_query_from_db and exec_procedure_from_db functions, designed to interact with a SQL Server database. It supports executing queries or stored procedures, and optionally creating backups of tables.

Function Usage

  • get_query_from_db(query, table_to_backup, env_file_name=None, params=None):

    • Executes a SQL query on the database.
    • Parameters:
      • query: A SQL query string to execute on the database.
      • table_to_backup: The name of a table to back up. Set this to None if no backup is needed.
      • env_file_name (optional): The path to the .env file containing database credentials. Defaults to .env.
      • params (optional): A dictionary of parameters to bind to the query.
    • Returns:
      • A pandas DataFrame with the query results.
  • exec_procedure_from_db(procedure_name, table_to_backup, env_file_name=None, params=None):

    • Executes a stored procedure on the database.
    • Parameters:
      • procedure_name: The name of the stored procedure to execute.
      • table_to_backup: The name of a table to back up. Set this to None if no backup is needed.
      • env_file_name (optional): The path to the .env file containing database credentials. Defaults to .env.
      • params (optional): A dictionary of parameters to bind to the procedure.
    • Returns:
      • A pandas DataFrame with the procedure's output.

Setup Instructions

  1. Environment Variables:
    • The script requires a .env file to load database credentials and connection details.
    • Required variables:
      USER=
      PASSWORD=
      HOST=
      NAME=
      DRIVER=ODBC+Driver+17+for+SQL+Server
      
      Fill in the variables with your database details. Leave DRIVER unchanged unless you are using a different driver.

Installation

Install the package directly from PyPI:

pip install Credito_SQLViaCode

#### Examples:

- **Execute a Query**:
   ```python
   from SQLViaCode import get_query_from_db

   query = "SELECT * FROM your_table"
   result_df = get_query_from_db(query, "your_table_to_backup")
   print(result_df)

Metadata

Release files for Credito-SQLViaCode 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Credito-SQLViaCode 0.2.1
File Size Uploaded
Credito_SQLViaCode-0.2.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Credito-SQLViaCode 0.2.1
File Interpreter ABI Platform
Credito_SQLViaCode-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / Credito_SQLViaCode-0.2.1.tar.gz

Download URL Credito_SQLViaCode-0.2.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2427ca60ed0abe786920096f8bc347515035456fed5c1d4e5ec091d376917a83
BLAKE2b-256 checksum
How to use checksums
1447e9938afc67d0e5bf8ebe9ea4f4d65f93caf95dabb7eb392c497c8d00b127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.9

Release files / Credito_SQLViaCode-0.2.1-py3-none-any.whl

Download URL Credito_SQLViaCode-0.2.1-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ef7cfdc1e46d244b1b2d263dd8e7373379bbf47e6d75d4af7c056ba2b9478fe
BLAKE2b-256 checksum
How to use checksums
6efd1b61932d4e2ba4bd7938ffc9f2795febd3855f37286fcac1a37c93730cbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page