{"id":20280327,"url":"https://github.com/yezz123/pgqb","last_synced_at":"2025-07-03T11:02:34.910Z","repository":{"id":226637171,"uuid":"767791007","full_name":"yezz123/pgqb","owner":"yezz123","description":"Typed Python PostgreSQL query builder ✨","archived":false,"fork":false,"pushed_at":"2025-06-02T21:07:00.000Z","size":205,"stargazers_count":7,"open_issues_count":9,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-03T11:31:49.045Z","etag":null,"topics":["postgresql","pydantic","query","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yezz123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"yezz123","polar":"yezz123"}},"created_at":"2024-03-05T22:45:34.000Z","updated_at":"2024-12-30T22:29:18.000Z","dependencies_parsed_at":"2024-03-11T16:04:46.245Z","dependency_job_id":"333b7a80-3c70-477e-9001-3e4451aefc81","html_url":"https://github.com/yezz123/pgqb","commit_stats":null,"previous_names":["yezz123/pgqb"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yezz123/pgqb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezz123%2Fpgqb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezz123%2Fpgqb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezz123%2Fpgqb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezz123%2Fpgqb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yezz123","download_url":"https://codeload.github.com/yezz123/pgqb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezz123%2Fpgqb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263314092,"owners_count":23447289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["postgresql","pydantic","query","sql"],"created_at":"2024-11-14T13:35:19.164Z","updated_at":"2025-07-03T11:02:34.836Z","avatar_url":"https://github.com/yezz123.png","language":"Python","readme":"# PostgreSQL Query Builder\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/yezz123/pgqb\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/yezz123/pgqb/main/.github/logo.png\" alt=\"pgqb\"\u003e\n\u003c/a\u003e\n\u003cp align=\"center\"\u003e\n    \u003cem\u003eTyped Python PostgreSQL query builder ✨\u003c/em\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/yezz123/pgqb/actions/workflows/ci.yml\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://github.com/yezz123/pgqb/actions/workflows/ci.yml/badge.svg\" alt=\"Continuous Integration\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/pgqb\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/pgqb?color=%2334D058\u0026label=pypi%20package\" alt=\"Package version\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/yezz123/pgqb\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/yezz123/pgqb/branch/main/graph/badge.svg\"/\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\u003c/p\u003e\n\n---\n\n**Source Code**: \u003chttps://github.com/yezz123/pgqb\u003e\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, and_, join, 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(\n        User.id,\n    )\n    .from_(User, join(Task).on(Task.user_id == User.id))\n    .where(User.id == 1, and_(Task.id == 1))\n    .order_by(\n        Task.value.desc(),\n    )\n).prepare()\n\nexpected = \" \".join(\n    [\n        'SELECT \"user\".id',\n        'FROM \"user\"',\n        'JOIN \"task\" ON \"task\".user_id = \"user\".id',\n        'WHERE \"user\".id = ?',\n        'AND \"task\".id = ?',\n        'ORDER BY \"task\".value DESC',\n    ]\n)\n\nprint(sql == expected)\n\n# \u003e\u003e\u003e 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\u003e **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 🌝\n\nYou can run all the tests with:\n\n```bash\nbash scripts/tests.sh\n```\n\n### Format the code 🍂\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 🍻\n\nThis project is licensed under the terms of the MIT license.\n","funding_links":["https://github.com/sponsors/yezz123","https://polar.sh/yezz123"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyezz123%2Fpgqb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyezz123%2Fpgqb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyezz123%2Fpgqb/lists"}