semvec/pypi-packages huggingface dataset:
etb-pg 0.1.6
Interface for PostgreSQL databases
License: MIT
Requires Python: <4.0,>=3.10

# PG Library

A small class for interacting with Postgres databases. Developed for the CS 495 TV Manager project.

## Initialize

Pass a dictionary with connection credentials when instantiating the PGDB object.
```
conn_dict: dict = {
    "user" : "",        # default $USER
    "password" : "",    # default None
    "host" : "",        # default localhost
    "port" : "",        # default 5432
    "dbname" : ""       # default $USER
}
```
All of the connection params are optional, and default to the regular Postgres defaults (commented above).

Optional args are read_only connection (default True) and an SQL directory where the object will check for queries stored as as readable files (default None).


## Usage

You can execute a query from a file, from a raw string, from a decorated function, or run a very simple select query. As with the actual Postgres database, schema is always an optional argument, and always defaults to "public" if not provided. Results of a query are always returned as a list of dictionaries, in which the column name maps to the value.

execute_file_query(): If no SQL directory is passed when the object is created, then it will assume you're passing with an absolute file path. If there is no file extension included in the method call, then it will assume it's looking for a .sql file. If you did pass an SQL directory at instantiation, and you're using .sql file extensions, you can just pass the name of the file as a string without path or extension. For example, if you initialized the PGDB object with sql_dir = '/home/app/SQL', you can execute the query in '/home/app/SQL/my_query.sql' with execute_file_query('my_query').

execute_str_query(): Execute a raw string query.

str_to_query(): Use this to decorate a function that returns a string. Could be useful for mildly dynamic queries. For example (assuming you have already created a PGDB object called "pg_interface"):

```
@pg_interface.str_to_query
def foo(cols: list[str], identifier: str) -> str:
    columns = ', st.'.join(cols)

    query = f"""select st.{columns}
            from schema.table_name st
            where st.id = '{identifier}'"""
    
    return query
```

Using the decorator, foo() will return the result of the query.

get_columns(): Not a query function. Will return a list of {column_name : python_type} for the specified schema/table.

get_rows(): Will return the results of a query that selects the specified columns from the specified schema/table.


There are no methods for doing joins or window functions- I want to keep any logic that's even remotely complex in a version controlled .sql file, or let the user wrap the logic in a decorated function. There's also nothing for creates/updates/deletes or anything like that- I want to leave the real ELT to another application or library or framework better suited for it. You can use the get_rows() method for very simple, unqualified selects from a table (or, preferably, a view or function).
django-db-purge 0.2
Clean up your Django database effortlessly with customizable record removal based on your retention policy
License: MIT

---

## Django Database Purge

The Django Database Purge management command is a tool for efficiently removing unwanted records from your Django project's database based on a specified retention policy. This command helps you keep your database clean and optimized by permanently deleting records that are no longer needed.

### Features:

- **Flexible Retention Policy**: Define your own retention policy to determine which records should be purged from the database.
- **Efficient Data Management**: Easily manage the size of your database by removing outdated or unnecessary records.
- **Customizable**: Adapt the command to suit your project's specific requirements and database structure.
- **Safe**: Built-in safeguards to prevent accidental data loss, ensuring that only the intended records are purged.

### How to Use:
1. Install django-db-purge by running:
```bash
pip install django-db-purge
```
2. Include 'dbpurge' in your INSTALLED_APPS settings. 
3. Locate the `db_purge.py` file in the `management/commands` directory of the Django dbpurge app.
4. Add your own values to the retention policies dictionary in the `db_purge.py` file, based on your requirements. Below is a guide on how to set up the retention policies:

    #### 1. `app_name`

    - **Description**: Name of the Django app containing the model.
    - **Example**: `my_django_app`

    #### 2. `model_name`

    - **Description**: Name of the Django model from which records will be deleted.
    - **Example**: `MyModel`

    #### 3. `time_based_column_name`

    - **Description**: Name of the column in the model that contains the timestamp or datetime field used for determining the age of records.
    - **Example**: `created_at`

    #### 4. `data_retention_num_seconds`

    - **Description**: Time duration in seconds for which records will be retained before deletion.
    - **Example**: `2592000` (for 30 days)

    #### Example:

    ```python
    retention_policies = [
        {
            'app_name': 'my_django_app',
            'model_name': 'MyModel',
            'time_based_column_name': 'created_at',
            'data_retention_num_seconds': 2592000,  # 30 days in seconds
        },
        # Add more retention policies as needed
    ]
    ```
5. Then, either periodically call the db_purge management command (e.g., via a system cronjob), or install and configure django-cron.

### Contributions:

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please submit an issue or pull request on GitHub.

### License:

This project is licensed under the MIT License.

---