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 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xbot_plugins_pgsql-0.2.2.tar.gz | 32.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xbot_plugins_pgsql-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.9 kB
Release files / xbot_plugins_pgsql-0.2.2.tar.gz
| Download URL | xbot_plugins_pgsql-0.2.2.tar.gz |
|---|---|
| Size | 32.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
748e480b90c872d01f8cd26c40845a4334b55db9d5773f195cb3efc4643ceb91
|
|
BLAKE2b-256 checksum How to use checksums |
54fdc36e4f64eb6c7a608f2b8b0d1363cc059dfe3c31834369829718a7674d52
|
| 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-0.2.2-py3-none-any.whl
| Download URL | xbot_plugins_pgsql-0.2.2-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a3b6204b1a8a1a3ad7a79857944ab90129720cc320f8bc3693d46f3735534604
|
|
BLAKE2b-256 checksum How to use checksums |
17ec96927ae2a3affff00be620f44c8b2c367b0812ce20a21d8d2edbcf188e7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|