Skip to main content

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

Demo Project

Here is a demo project showing how to use xbot.plugins.pgsql in a test project.


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

示例项目

展示如何在一个测试项目中使用本插件的示例:demo

Metadata

Release files for xbot.plugins.pgsql 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xbot.plugins.pgsql 1.0.0
File Size Uploaded
xbot_plugins_pgsql-1.0.0.tar.gz 14.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xbot.plugins.pgsql 1.0.0
File Interpreter ABI Platform
xbot_plugins_pgsql-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.4 kB

Release files / xbot_plugins_pgsql-1.0.0.tar.gz

Download URL xbot_plugins_pgsql-1.0.0.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
279597f3707b187d604e03bc90478bece0ba80f770d7e0d5d7592f81f6429793
BLAKE2b-256 checksum
How to use checksums
6521760546639f61d3beb98d413b118133b1cd595728ba0223a385a8b69f55a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / xbot_plugins_pgsql-1.0.0-py3-none-any.whl

Download URL xbot_plugins_pgsql-1.0.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19889cbcd969ecda3b06640a519d8759ac39533bc52de65802e948c1ecf336d4
BLAKE2b-256 checksum
How to use checksums
53236e69ff2b363b8b3ce5fc5818b1afbee5ee9db3c77b102529fee5cbb8f071
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page