pgqb


Namepgqb JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryTyped Python PostgreSQL query builder using Pydantic
upload_time2024-03-09 02:52:27
maintainer
docs_urlNone
author
requires_python>=3.9
license
keywords postgresql pydantic query
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PostgreSQL Query Builder

<p align="center">
<a href="https://github.com/yezz123/pgqb" target="_blank">
    <img src="https://raw.githubusercontent.com/yezz123/pgqb/main/.github/logo.png" alt="pgqb">
</a>
<p align="center">
    <em>Typed Python PostgreSQL query builder ✨</em>
</p>
<p align="center">
<a href="https://github.com/yezz123/pgqb/actions/workflows/ci.yml" target="_blank">
    <img src="https://github.com/yezz123/pgqb/actions/workflows/ci.yml/badge.svg" alt="Continuous Integration">
</a>
<a href="https://pypi.org/project/pgqb" target="_blank">
    <img src="https://img.shields.io/pypi/v/pgqb?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://codecov.io/gh/yezz123/pgqb">
    <img src="https://codecov.io/gh/yezz123/pgqb/branch/main/graph/badge.svg"/>
</a>
</p>
</p>

---

**Source Code**: <https://github.com/yezz123/pgqb>

**Documentation**: TBD

---

pgqb is a Python library for building SQL queries for PostgreSQL databases. It provides a simple and intuitive interface for constructing SQL statements using functions like `delete`, `insert_into`, `select`, and `update`. This README provides a brief overview of how to use pgqb to build queries and execute them safely with parameter binding.

## Installation

You can install pgqb via pip:

```bash
pip install pgqb
```

## Project using

```py
from pgqb import Column, Table, select


class User(Table):
    id = Column()
    first = Column()
    last = Column()


class Task(Table):
    id = Column()
    user_id = Column()
    value = Column()


sql, params = (
    select(User)
    .from_(User)
    .join(Task)
    .on(Task.user_id == User.id)
    .where(User.id == 1)
    .order_by(Task.value.desc())
).prepare()

expected = " ".join(
    [
        'SELECT "user".id, "user".first, "user".last',
        'FROM "user"',
        'JOIN "task" ON "task".user_id = "user".id',
        'WHERE "user".id = ?',
        'ORDER BY "task".value DESC',
    ]
)


print(sql==expected)
# > True
```

### Create Table

```py
from pgqb import Column, Table, TEXT, TIMESTAMP, UUID


class User(Table):
    id = Column(UUID(), primary=True)
    email = Column(TEXT(), unique=True, index=True)
    first = Column(TEXT())
    last = Column(TEXT())
    verified_at = Column(TIMESTAMP(with_time_zone=True))

print(User.create_table())

# > CREATE TABLE IF NOT EXISTS "user" (
#  "id" UUID,
#  "email" TEXT NOT NULL UNIQUE,
#  "first" TEXT NOT NULL,
#  "last" TEXT NOT NULL,
#  "verified_at" TIMESTAMP WITH TIME ZONE NOT NULL,
#  PRIMARY KEY (id)
#);
# CREATE INDEX ON "user" (email);
```

## Development

### Setup environment

You should create a virtual environment and activate it:

> **Notes:** You need to have `python3.9` or higher installed.

I Use `uv` to manage virtual environments, you can install it with:

```bash
# Install uv
pip install uv

# Create a virtual environment
uv venv

# Activate the virtual environment
source .venv/bin/activate
```

And then install the development dependencies:

```bash
# Install dependencies
uv pip install -e .[test,lint]
```

### Run tests 🌝

You can run all the tests with:

```bash
bash scripts/tests.sh
```

### Format the code 🍂

Execute the following command to apply `pre-commit` formatting:

```bash
bash scripts/format.sh
```

Execute the following command to apply `mypy` type checking:

```bash
bash scripts/lint.sh
```

## License 🍻

This project is licensed under the terms of the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pgqb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "PostgreSQL,Pydantic,Query",
    "author": "",
    "author_email": "Yasser Tahiri <hello@yezz.me>",
    "download_url": "https://files.pythonhosted.org/packages/c9/aa/6866a4702ff0436f182d0406ca43dbf682867ad104ddd6a0254af98adaac/pgqb-0.1.0.tar.gz",
    "platform": null,
    "description": "# PostgreSQL Query Builder\n\n<p align=\"center\">\n<a href=\"https://github.com/yezz123/pgqb\" target=\"_blank\">\n    <img src=\"https://raw.githubusercontent.com/yezz123/pgqb/main/.github/logo.png\" alt=\"pgqb\">\n</a>\n<p align=\"center\">\n    <em>Typed Python PostgreSQL query builder \u2728</em>\n</p>\n<p align=\"center\">\n<a href=\"https://github.com/yezz123/pgqb/actions/workflows/ci.yml\" target=\"_blank\">\n    <img src=\"https://github.com/yezz123/pgqb/actions/workflows/ci.yml/badge.svg\" alt=\"Continuous Integration\">\n</a>\n<a href=\"https://pypi.org/project/pgqb\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/v/pgqb?color=%2334D058&label=pypi%20package\" alt=\"Package version\">\n</a>\n<a href=\"https://codecov.io/gh/yezz123/pgqb\">\n    <img src=\"https://codecov.io/gh/yezz123/pgqb/branch/main/graph/badge.svg\"/>\n</a>\n</p>\n</p>\n\n---\n\n**Source Code**: <https://github.com/yezz123/pgqb>\n\n**Documentation**: TBD\n\n---\n\npgqb is a Python library for building SQL queries for PostgreSQL databases. It provides a simple and intuitive interface for constructing SQL statements using functions like `delete`, `insert_into`, `select`, and `update`. This README provides a brief overview of how to use pgqb to build queries and execute them safely with parameter binding.\n\n## Installation\n\nYou can install pgqb via pip:\n\n```bash\npip install pgqb\n```\n\n## Project using\n\n```py\nfrom pgqb import Column, Table, select\n\n\nclass User(Table):\n    id = Column()\n    first = Column()\n    last = Column()\n\n\nclass Task(Table):\n    id = Column()\n    user_id = Column()\n    value = Column()\n\n\nsql, params = (\n    select(User)\n    .from_(User)\n    .join(Task)\n    .on(Task.user_id == User.id)\n    .where(User.id == 1)\n    .order_by(Task.value.desc())\n).prepare()\n\nexpected = \" \".join(\n    [\n        'SELECT \"user\".id, \"user\".first, \"user\".last',\n        'FROM \"user\"',\n        'JOIN \"task\" ON \"task\".user_id = \"user\".id',\n        'WHERE \"user\".id = ?',\n        'ORDER BY \"task\".value DESC',\n    ]\n)\n\n\nprint(sql==expected)\n# > True\n```\n\n### Create Table\n\n```py\nfrom pgqb import Column, Table, TEXT, TIMESTAMP, UUID\n\n\nclass User(Table):\n    id = Column(UUID(), primary=True)\n    email = Column(TEXT(), unique=True, index=True)\n    first = Column(TEXT())\n    last = Column(TEXT())\n    verified_at = Column(TIMESTAMP(with_time_zone=True))\n\nprint(User.create_table())\n\n# > CREATE TABLE IF NOT EXISTS \"user\" (\n#  \"id\" UUID,\n#  \"email\" TEXT NOT NULL UNIQUE,\n#  \"first\" TEXT NOT NULL,\n#  \"last\" TEXT NOT NULL,\n#  \"verified_at\" TIMESTAMP WITH TIME ZONE NOT NULL,\n#  PRIMARY KEY (id)\n#);\n# CREATE INDEX ON \"user\" (email);\n```\n\n## Development\n\n### Setup environment\n\nYou should create a virtual environment and activate it:\n\n> **Notes:** You need to have `python3.9` or higher installed.\n\nI Use `uv` to manage virtual environments, you can install it with:\n\n```bash\n# Install uv\npip install uv\n\n# Create a virtual environment\nuv venv\n\n# Activate the virtual environment\nsource .venv/bin/activate\n```\n\nAnd then install the development dependencies:\n\n```bash\n# Install dependencies\nuv pip install -e .[test,lint]\n```\n\n### Run tests \ud83c\udf1d\n\nYou can run all the tests with:\n\n```bash\nbash scripts/tests.sh\n```\n\n### Format the code \ud83c\udf42\n\nExecute the following command to apply `pre-commit` formatting:\n\n```bash\nbash scripts/format.sh\n```\n\nExecute the following command to apply `mypy` type checking:\n\n```bash\nbash scripts/lint.sh\n```\n\n## License \ud83c\udf7b\n\nThis project is licensed under the terms of the MIT license.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Typed Python PostgreSQL query builder using Pydantic",
    "version": "0.1.0",
    "project_urls": {
        "Funding": "https://github.com/sponsors/yezz123",
        "Homepage": "https://github.com/yezz123/pgqb"
    },
    "split_keywords": [
        "postgresql",
        "pydantic",
        "query"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "57744f97329ebfe94437961ec62b016cddbf00a4fe238d507794161342e60740",
                "md5": "b00386bbf385cbcd1cb911f6280c05c0",
                "sha256": "c77618005178c55c42ecae63d5df7efda1aedcae3f7d8841834576e37c9a5978"
            },
            "downloads": -1,
            "filename": "pgqb-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b00386bbf385cbcd1cb911f6280c05c0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 12128,
            "upload_time": "2024-03-09T02:52:25",
            "upload_time_iso_8601": "2024-03-09T02:52:25.222610Z",
            "url": "https://files.pythonhosted.org/packages/57/74/4f97329ebfe94437961ec62b016cddbf00a4fe238d507794161342e60740/pgqb-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9aa6866a4702ff0436f182d0406ca43dbf682867ad104ddd6a0254af98adaac",
                "md5": "652c9bdb55a2e7b0499deeb8daa52333",
                "sha256": "afb61c05cd244ccf9f04bbc6510296a12af9f6b2caaf526e4183215bb109d6fa"
            },
            "downloads": -1,
            "filename": "pgqb-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "652c9bdb55a2e7b0499deeb8daa52333",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 92450,
            "upload_time": "2024-03-09T02:52:27",
            "upload_time_iso_8601": "2024-03-09T02:52:27.301620Z",
            "url": "https://files.pythonhosted.org/packages/c9/aa/6866a4702ff0436f182d0406ca43dbf682867ad104ddd6a0254af98adaac/pgqb-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-09 02:52:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sponsors",
    "github_project": "yezz123",
    "github_not_found": true,
    "lcname": "pgqb"
}
        
Elapsed time: 0.29872s