Skip to main content

PostgreSQL library for xbot.framework

Project description


English | 中文


xbot.plugins.pgsql

PostgreSQL library for xbot.framework.

Introduction

A synchronous PostgreSQL client library for xbot.framework, built on Psycopg 3. It provides a thin connection wrapper with SQLSTATE-based expectation checking, psql-style result rendering, and explicit transaction support.

Python >= 3.10, PostgreSQL >= 14. For full API documentation, refer to the docstrings in each module.

Installation

pip install xbot.plugins.pgsql

Getting Started

from xbot.plugins.pgsql import PGCodes, PGSQLConnection

db = PGSQLConnection()
db.connect(
    host="127.0.0.1",
    user="postgres",
    password="secret",
    database="postgres",
)

result = db.exec(
    "SELECT 1::integer AS id, 'alice'::text AS name",
)
print(result)
print(result.header)
print(result.rc)
print(result.cmd)

missing = db.exec(
    "SELECT * FROM missing_table",
    expect=PGCodes.UNDEFINED_TABLE,
)
assert missing.rc == "42P01"

with db.transaction():
    db.exec("INSERT INTO accounts(id, balance) VALUES (1, 100)")

db.disconnect()


中文 | English


xbot.plugins.pgsql

xbot.framework 的 PostgreSQL 客户端库。

简介

基于 Psycopg 3 的同步 PostgreSQL 客户端库,面向 xbot.framework。提供薄封装连接,支持基于 SQLSTATE 的预期检查、psql 风格结果渲染和显式事务。

Python >= 3.10,PostgreSQL >= 14。完整 API 文档请参阅各模块的 docstring。

安装

pip install xbot.plugins.pgsql

入门

from xbot.plugins.pgsql import PGCodes, PGSQLConnection

db = PGSQLConnection()
db.connect(
    host="127.0.0.1",
    user="postgres",
    password="secret",
    database="postgres",
)

result = db.exec(
    "SELECT 1::integer AS id, 'alice'::text AS name",
)
print(result)
print(result.header)
print(result.rc)
print(result.cmd)

missing = db.exec(
    "SELECT * FROM missing_table",
    expect=PGCodes.UNDEFINED_TABLE,
)
assert missing.rc == "42P01"

with db.transaction():
    db.exec("INSERT INTO accounts(id, balance) VALUES (1, 100)")

db.disconnect()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xbot_plugins_pgsql-0.1.0.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xbot_plugins_pgsql-0.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file xbot_plugins_pgsql-0.1.0.tar.gz.

File metadata

  • Download URL: xbot_plugins_pgsql-0.1.0.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for xbot_plugins_pgsql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fbd40f0aa2b528a7b9affbd90d2a2418a984c84105a47ec1a5ff215419d7a026
MD5 d4717055425562d8a93099c9fa49fdeb
BLAKE2b-256 d3dd7c3f55d1a089d7edc093618a3e0f8db0161435d49da40e89589443d2ae7f

See more details on using hashes here.

File details

Details for the file xbot_plugins_pgsql-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xbot_plugins_pgsql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58b330ad7e1d819a9a068e67cee910135212d1501b6136c7a6ab170f0f3396fa
MD5 882f8dcb1b952a89fc353d3d885642f1
BLAKE2b-256 6572bf6d772cecb5d4c451d06b519670a78ab17998d1acb9db143210aab8e97d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page