PostgreSQL library for xbot.framework
Project description
English | 中文
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()
中文 | English
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xbot_plugins_pgsql-0.1.0.tar.gz.
File metadata
- Download URL: xbot_plugins_pgsql-0.1.0.tar.gz
- Upload date:
- Size: 32.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbd40f0aa2b528a7b9affbd90d2a2418a984c84105a47ec1a5ff215419d7a026
|
|
| MD5 |
d4717055425562d8a93099c9fa49fdeb
|
|
| BLAKE2b-256 |
d3dd7c3f55d1a089d7edc093618a3e0f8db0161435d49da40e89589443d2ae7f
|
File details
Details for the file xbot_plugins_pgsql-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xbot_plugins_pgsql-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58b330ad7e1d819a9a068e67cee910135212d1501b6136c7a6ab170f0f3396fa
|
|
| MD5 |
882f8dcb1b952a89fc353d3d885642f1
|
|
| BLAKE2b-256 |
6572bf6d772cecb5d4c451d06b519670a78ab17998d1acb9db143210aab8e97d
|