11 Star 6 Fork 5

openGauss / openGauss-connector-python-pyog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

关于

该驱动是基于 py-postgresql 1.3.0 版本进行修改的,新增了两个特性:

  • 支持 openGauss 数据库连接
  • 支持多 IP 连接

安装方式

通过 pypi.org:

$ pip install py-opengauss

通过源码安装:

$ git clone https://gitee.com/opengauss/openGauss-connector-python-pyog.git
$ cd py-opengauss
$ python3 setup.py install

连接方式:

支持的连接协议列表: ['pq', 'postgres', 'postgresql', 'og', 'opengauss']

>>> import py_opengauss
# General Format:
>>> db = py_opengauss.open('pq://user:password@host:port/database')

# Also support opengauss scheme:
>>> db = py_opengauss.open('opengauss://user:password@host:port/database')

# multi IP support, will return PRIMARY instance connect:
>>> db = py_opengauss.open('opengauss://user:password@host1:123,host2:456/database')

# Connect to 'postgres' at localhost with default user and password in the env, which only support postgresql.
# 注意: 该连接方式只支持PG, 不支持openGauss, 对于openGauss, 必须要输入user和password
>>> db = py_opengauss.open('localhost/postgres')

基本用法

import py_opengauss
db = py_opengauss.open('opengauss://user:password@host:port/database')

get_table = db.prepare("SELECT * from information_schema.tables WHERE table_name = $1")
print(get_table("tables"))

# Streaming, in a transaction.
with db.xact():
    for x in get_table.rows("tables"):
        print(x)

sqlalchemy 多IP连接用法

注:sqlalchemy 目前本身是不支持 py_opengauss 包的

由于 sqlalchemy 在内部会解析连接串,且目前仅支持单个IP的连接串。 所以需下载定制后的 sqlalchemy 手动安装使用

https://github.com/vimiix/sqlalchemy

该定制版本在内部增加了对于 py_opengauss 包的支持,且支持了多IP连接串。

使用方式
from sqlalchemy import create_engine
# 初始化opengauss数据库多主机连接(适用于没有固定虚拟IP的数据库主备集群):
engine = create_engine('postgresql+pyopengauss://user:password@host1:port1,host2:port2/db')

Documentation

http://py-postgresql.readthedocs.io

Related

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the James William Pye nor the names of [its] contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
Python 等 2 种语言
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/opengauss/openGauss-connector-python-pyog.git
git@gitee.com:opengauss/openGauss-connector-python-pyog.git
opengauss
openGauss-connector-python-pyog
openGauss-connector-python-pyog
master

搜索帮助