Skip to content

Commit

Permalink
postql
Browse files Browse the repository at this point in the history
  • Loading branch information
Abel Tavares committed Feb 28, 2024
1 parent 0605d70 commit 5b44d32
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 63 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/run_black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels" \
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--header "Content-Type: application/json" \
--data-raw '{"labels": ["Formatter Failed"]}'
--data-raw '{"labels": ["formatter failed"]}'
- name: Check and remove label if sucess
if: success()
Expand All @@ -35,4 +35,5 @@ jobs:
curl --request DELETE \
--url "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels/Formatter%20Failed" \
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"
fi
fi
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- id: black

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# PostQL
---

PostQL is a Python library and command-line interface (CLI) tool for managing PostgreSQL databases, executing queries, exporting data and interacting with PostgreSQL databases from the command line.

## Features
---

- Connect to PostgreSQL databases and execute SQL queries interactively via the CLI.
- Perform database management tasks such as creating, deleting databases, users, tables, etc.
- Execute SQL queries directly from Python code using the `Postgres` class.
- Export query results to CSV, Excel, JSON, and Parquet formats.
- Upload exported files to Amazon S3 buckets.

## Installation
---

You can install PostQL via pip:

```bash
pip install postql
```
## Usage
---

### Command Line Interface (CLI)

To use the PostQL CLI, simply run `postql` followed by the desired command. Here are some examples:
Expand Down Expand Up @@ -56,9 +56,9 @@ db.select(table="users") \
```

## Documentation
---
- [Methods Documentation](docs/methods.md)
- [CLI Documentation](docs/cli/index.md)

- [Methods Documentation](https://abeltavares.github.io/PostQL/methods.html)
- [CLI Documentation](https://abeltavares.github.io/PostQL/cli.html)

## Contributing

Expand Down
14 changes: 5 additions & 9 deletions docs/cli/index.md → docs/cli.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CLI Documentation for PostQL
---
# CLI Documentation

## Installation
---

To install PostQL, you can use pip, the Python package installer. Open your terminal and run the following command:

```bash
Expand All @@ -11,7 +11,7 @@ pip install postql
This command installs PostQL and its dependencies.

## Usage
---

PostQL is a command-line interface for interacting with PostgreSQL databases. It allows you to connect to a database and execute SQL queries.

### Basic Usage
Expand Down Expand Up @@ -57,12 +57,8 @@ postql -h
```

## Troubleshooting
---

### Common Issues

- **Connection Issues**: Ensure that the database host, port, user, and password are correct. Also, verify that the database server is running and accessible.
- **SQL Errors**: Check your SQL queries for syntax errors. PostQL will display error messages if it encounters an issue executing a query.

## License
---
PostQL is open-source software licensed under the [MIT License](../../LICENSE.txt).
75 changes: 75 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# PostQL

PostQL is a Python library and command-line interface (CLI) tool for managing PostgreSQL databases, executing queries, exporting data and interacting with PostgreSQL databases from the command line.

## Features

- Connect to PostgreSQL databases and execute SQL queries interactively via the CLI.
- Perform database management tasks such as creating, deleting databases, users, tables, etc.
- Execute SQL queries directly from Python code using the `Postgres` class.
- Export query results to CSV, Excel, JSON, and Parquet formats.
- Upload exported files to Amazon S3 buckets.

## Installation

You can install PostQL via pip:

```bash
pip install postql
```
## Usage

### Command Line Interface (CLI)

To use the PostQL CLI, simply run `postql` followed by the desired command. Here are some examples:

```bash
# Connect to a database and execute SQL queries interactively
postql connect -H localhost -u postgres -P password -d my_database

# Run query
my_database> Select * from my_table

# Exit the CLI
exit

```
### Python Library

```python
from postql import Postgres

# Create a connection to the database
db = Postgres(host="localhost", port="5432", user="postgres", password="password")

# Connect to a specific database
db.connect(database="my_database")

# Execute SQL queries
db.sql("SELECT * FROM my_table")

# Export query results
db.select(table="users") \
.where({'age': ('>', 25)}) \
.to_csv("users_result.csv")

```

## Documentation

- [Methods Documentation](methods.md)
- [CLI Documentation](cli.md)

## Contributing

Contributions are welcome! If you find any bugs or have suggestions for improvement, please open an issue or submit a pull request.

The codebase of this project follows the [black](https://github.com/psf/black) code style. To ensure consistent formatting, the [pre-commit](https://pre-commit.com/) hook is set up to run the black formatter before each commit.

Additionally, a GitHub Action is configured to automatically run the black formatter on every pull request, ensuring that the codebase remains formatted correctly.

Please make sure to run `pip install pre-commit` and `pre-commit install` to enable the pre-commit hook on your local development environment.

## License

This project is licensed under the MIT License - see the [LICENSE](../LICENSE.txt) for details.
64 changes: 32 additions & 32 deletions docs/methods.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
# Methods Description
---------------

[Creating a PostgreSQL Instance](#creating-a-postgresql-instance)
- [Database Management Methods](#database-management-methods)
- [connect(database)](#connectdatabase)
- [disconnect()](#disconnect)
- [create_database(new_database)](#create_databasenew_database)
- [delete_database(database_to_delete)](#delete_databasedatabase_to_delete)
- [create_user(username, password, is_superuser)](#create_userusername-password-is_superuser)
- [delete_user(username)](#delete_userusername)
- [create_table(name, schema)](#create_tablename-schema)
- [drop_table(name)](#drop_tablename)
- [get_table_schema(table)](#get_table_schematable)
- [get_connection_details()](#get_connection_details)
- [connect (database)](#connectdatabase)
- [disconnect ()](#disconnect)
- [create_database (new_database)](#create_databasenew_database)
- [delete_database (database_to_delete)](#delete_databasedatabase_to_delete)
- [create_user (username, password, is_superuser)](#create_userusername-password-is_superuser)
- [delete_user (username)](#delete_userusername)
- [create_table (name, schema)](#create_tablename-schema)
- [drop_table (name)](#drop_tablename)
- [get_table_schema (table)](#get_table_schematable)
- [get_connection_details ()](#get_connection_details)
<br>

- [Data Operations Methods](#data-operations-methods)
- [select(table, columns=None)](#selecttable-columnsnone)
- [insert(table, data)](#inserttable-data)
- [update(table)](#updatetable)
- [set(data)](#setdata)
- [delete(table)](#deletetable)
- [join(table, join_type="INNER")](#jointable-join_typeinner)
- [on(condition)](#oncondition)
- [where(conditions)](#whereconditions)
- [order(columns, asc=False)](#ordercolumns-ascfalse)
- [groupby(columns)](#groupbycolumns)
- [limit(limit_value)](#limitlimit_value)
- [execute()](#execute)
- [sql(query)](#sqlquery)
- [select (table, columns=None)](#selecttable-columnsnone)
- [insert (table, data)](#inserttable-data)
- [update (table)](#updatetable)
- [set (data)](#setdata)
- [delete (table)](#deletetable)
- [join (table, join_type="INNER")](#jointable-join_typeinner)
- [on (condition)](#oncondition)
- [where (conditions)](#whereconditions)
- [order (columns, asc=False)](#ordercolumns-ascfalse)
- [groupby (columns)](#groupbycolumns)
- [limit (limit_value)](#limitlimit_value)
- [execute ()](#execute)
- [sql (query)](#sqlquery)


- *Data Exportation*
- [to_csv(output_file)](#to_csvoutput_file)
- [to_excel(output_file)](#to_exceloutput_file)
- [to_json(output_file)](#to_jsonoutput_file)
- [to_parquet(output_file)](#to_parquetoutput_file)
- [upload_to_s3(bucket_name, format, filename, acl=None, metadata=None)](#upload_to_s3bucket_name-format-filename-aclnone-metadatanone)
- [to_csv (output_file)](#to_csvoutput_file)
- [to_excel (output_file)](#to_exceloutput_file)
- [to_json (output_file)](#to_jsonoutput_file)
- [to_parquet (output_file)](#to_parquetoutput_file)
- [upload_to_s3 (bucket_name, format, filename, acl=None, metadata=None)](#upload_to_s3bucket_name-format-filename-aclnone-metadatanone)

<br>

### Creating a PostgreSQL Instance
---

Before you can perform any database management or data operations, you need to create an instance of the `Postgres` class. This instance represents a connection to a PostgreSQL database.

To create a PostgreSQL instance, you need to provide the connection details such as the host, port, user, and password.
Expand All @@ -50,7 +50,7 @@ db = Postgres( host="localhost", port="5432", user="my_user", password="my_passw
```

### Database Management Methods
---

#### `connect(database)`

The `connect` method establishes a connection to the PostgreSQL server.
Expand Down Expand Up @@ -297,7 +297,7 @@ Retrieving connection details is useful for troubleshooting and for verifying th
This documentation provides a comprehensive guide to using the `DatabaseManagement` class for managing PostgreSQL databases and users. It includes detailed descriptions of each method, along with examples of how to use them.

### Data Operations Methods
---

### `select(table, columns=None)`

The `select` method constructs a SELECT SQL query.
Expand Down
2 changes: 1 addition & 1 deletion postql/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "1.0.0"
21 changes: 10 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@

setup(
name="PostQL",
version="0.0.1",
version="1.0.0",
description="Python wrapper for Postgres",
long_description=long_description,
long_description_content_type="text/markdown",
author="Abel Tavares",
url="https://github.com/abeltavares/postql",
author_email="abelst9@gmail.com",
project_urls={
"Homepage": "https://abeltavares.github.io/PostQL/",
"Repository": "https://github.com/abeltavares/postql",
},
packages=["postql"],
entry_points={
"console_scripts": [
Expand All @@ -26,19 +31,13 @@
"boto3",
"openpyxl",
"pyarrow",
"csv",
"json",
"decimal",
"sys",
"tempfile",
"os",
"logging",
"argparse",
],
license="BSD",
classifiers=[
"License :: OSI Approved :: MIT License",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
"Topic :: Database",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3 :: Only",
],
)

0 comments on commit 5b44d32

Please sign in to comment.