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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xbot_plugins_pgsql-1.0.0.tar.gz | 14.4 kB | Without provenance | Details for xbot_plugins_pgsql-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xbot_plugins_pgsql-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for xbot_plugins_pgsql-1.0.0-py3-none-any.whl |
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
|
Security for xbot.plugins.pgsql 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.