Skip to main content

PostgreSQL library for xbot.framework

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xbot_plugins_pgsql-0.2.0.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xbot_plugins_pgsql-0.2.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file xbot_plugins_pgsql-0.2.0.tar.gz.

File metadata

  • Download URL: xbot_plugins_pgsql-0.2.0.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for xbot_plugins_pgsql-0.2.0.tar.gz
Algorithm Hash digest
SHA256 74850df3d7e2a8f20212149479263647b9160f7390f45c2e387301a951f692de
MD5 65e10ad5206851f2b5a23b130940f6fb
BLAKE2b-256 ff7574e306a0942a660b89adbb69d396058c64ed5c2df45bfece6560d82f287c

See more details on using hashes here.

File details

Details for the file xbot_plugins_pgsql-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xbot_plugins_pgsql-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46cb34e0152338bb809b95cb89d86c9e1f6b99ef7cfcebc51372e18893767ac7
MD5 87151c8974a1ee8dab404dd0ba7922d2
BLAKE2b-256 bbfea0d1d417617b0ead07282139e36880cdce27dc772096aa91c1aa33ff357c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page