Metadata-Version: 2.1
Name: connectors_to_databases
Version: 1.0.1
Summary: Python module for connect with PostgreSQL and ClickHouse 
Home-page: https://github.com/k0rsakov/connectors_to_databases
Download-URL: https://github.com/k0rsakov/connectors_to_databases/archive/refs/heads/main.zip
Author: k0rsakov
Author-email: korsakov.iyu@gmail.com
License: Apache License, Version 2.0, see LICENSE file
Keywords: database,SQL,PostgreSQL,ClickHouse,dataframe
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: End Users/Desktop
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.MD

# Connector to databases

![PyPI](https://img.shields.io/pypi/v/connectors-to-databases?color=blueviolet) 
![Python 3, 3.10, 3.11](https://img.shields.io/pypi/pyversions/clubhouse?color=blueviolet)
![License](https://img.shields.io/pypi/l/connectors-to-databases?color=blueviolet) 

**Connector to databases** – easy package for connect with database 
[PostgreSQL](https://github.com/postgres/postgres) and 
[ClickHouse](https://github.com/ClickHouse/ClickHouse)

## Installation

Install the current version with 
[PyPI](https://pypi.org/project/connectors-to-databases/):

```bash
pip install connectors-to-databases
```

Or from GitHub:

```bash
pip install https://github.com/k0rsakov/connectors_to_databases/archive/refs/heads/main.zip
```

## How to use class PostgreSQL

### Creating instance of class

You can create as many database connectors as you want.

```python
from connectors_to_databases import PostgreSQL

pg = PostgreSQL()

pg_other = PostgreSQL(
    host='0.0.0.0',
    port=0,
    database='main',
    login='admin',
    password='admin',
)
```

### Check connection to database

```python
pg.check_connection()
```

### Creating a table for examples

```python
pg.execute_script('CREATE TABLE simple_ (id int4)')
```

### Filling the table with data

```python
# simple pd.DataFrame
df = pd.DataFrame(data={'id':[1]})

pg.insert_df(
    df=df,
    pg_table_name='simple_'
)
```

### Getting data from a table

```python
pg.execute_to_df(
    '''select * from simple_'''
)
```

### Getting a connector to the database.

It can be used as you need.

```python
pg.get_uri()
```

What does the connector look like

```log
Engine(postgresql://postgres:***@localhost:5432/postgres)
```

### Delete our `simple_` table

```python
pg.execute_script('DROP TABLE simple_')
```

## How to use class ClickHouse

### Creating instance of class

You can create as many database connectors as you want.

```python
from connectors_to_databases import ClickHouse

ch = ClickHouse()

ch_other = ClickHouse(
    host='0.0.0.0',
    port=0,
    login='admin',
    password='admin',
)
```

### Creating a table for examples

```python
ch.execute_script(
    '''
    CREATE TABLE test 
    (
        value Int64
    ) 
    ENGINE = MergeTree 
    ORDER BY value
    '''
)
```

### Filling the table with data

```python
# simple pd.DataFrame
df = ch.DataFrame(data={'value':[1]})

ch.insert_df(
    df=df,
    pg_table_name='test'
)
```

### Getting data from a table

```python
ch.execute_to_df(
    '''select * from test'''
)
```

### Getting a connector to the database.

It can be used as you need.

```python
ch.get_uri()
```

What does the connector look like

```log
Engine(clickhouse://click:***@localhost:8123/default)
```

### Delete our `simple_` table

```python
ch.execute_script('DROP TABLE test')
```


## Contributing

Bug reports and/or pull requests are welcome

## License

The module is available as open source under the terms of the 
[Apache License, Version 2.0](https://opensource.org/licenses/Apache-2.0)
