Skip to main content

PostgreSQL library for xbot.framework

Project description

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()

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.1.tar.gz (32.6 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.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xbot_plugins_pgsql-0.1.1.tar.gz
  • Upload date:
  • Size: 32.6 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.1.tar.gz
Algorithm Hash digest
SHA256 3a73b11765dc1dca752266c096b12ccfadeadb67b739b6d80db58dd0c047723d
MD5 193bd0b343c77048559514dc979753ff
BLAKE2b-256 bf4f0b21e88aaee70d590d71891d25187b776c6b599ee4a419434c0e8adec2c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xbot_plugins_pgsql-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba1a3677336d88a35a956cd52c652dfba647ece7e20df51faf919ac08f879c6d
MD5 a87ec889dcc8de134350299ba9f375a4
BLAKE2b-256 8febc0b7c49d52dc51a6e5b4de32cd65eec24e9017c99f34739fd5bb801128b2

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