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.1
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.1.tar.gz | 32.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xbot_plugins_pgsql-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.9 kB
Release files / xbot_plugins_pgsql-0.2.1.tar.gz
| Download URL | xbot_plugins_pgsql-0.2.1.tar.gz |
|---|---|
| Size | 32.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6328642f5992efd6ebf857b5fd38a50c7b0f8c89be936f536ffcc266e205de24
|
|
BLAKE2b-256 checksum How to use checksums |
1d06c5f0cb20c415186832c5c53f9d53aa8bef5ffde49f13bf2eec96cd937aba
|
| 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.1-py3-none-any.whl
| Download URL | xbot_plugins_pgsql-0.2.1-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a206e44036ff325f265931ea43e332fe09434a0d94bb0b13fcec883860e95be
|
|
BLAKE2b-256 checksum How to use checksums |
65d464e3437a8c26d6e24f438651af739f5cfb91b2cd746193b344ce94e81131
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|