Fetch the repository succeeded.
OpenGauss dialect for SQLAlchemy.
This project has been tested with test suites of SQLAlchemy.
psycopg2 for opengauss
Download and install reference
https://gitee.com/opengauss/openGauss-connector-python-psycopg2
or
https://github.com/opengauss-mirror/openGauss-connector-python-psycopg2
# From pypi
>>> python -m pip install opengauss-sqlalchemy
# From source code
>>> python setup.py install
Create an DSN(Data Source Name) that points to your OpenGauss database.
>>> import sqlalchemy as sa
# With centralized mode
>>> sa.create_engine('opengauss://username:password@host:port/database_name')
# Or
>>> sa.create_engine('opengauss+psycopg2://username:password@host:port/database_name')
# With distributed mode
>>> sa.create_engine('opengauss+dc_psycopg2://username:password@host:port/database_name')
# Or
>>> sa.create_engine('opengauss+dc_psycopg2://username:password@/database_name?host=hostA:portA&host=hostB:portB')
See the OpenGauss DeveloperGuide for more infomation.
USING method
tbl = Table("testtbl", m, Column("data", String))
Index("test_idx1", tbl.c.data, opengauss_using="btree")
tbl = Table(
"testtbl",
m,
Column("data", String),
Column("data2", Integer, key="d2"),
)
Index(
"test_idx1",
tbl.c.data,
tbl.c.d2,
opengauss_ops={"data": "text_pattern_ops", "d2": "int4_ops"},
)
LOCAL
, only available for index on a partitioned tabletbl = Table(
"testtbl",
m,
Column("data", Integer),
opengauss_partition_by="RANGE (data) ..."
)
Index("test_idx1", tbl.c.data, opengauss_local=[""])
Index(
"test_idx2",
tbl.c.data,
opengauss_local=[
"PARTITION data_index1",
"PARTITION data_index2 TABLESPACE example3",
]
)
WITH
tbl = Table("testtbl", m, Column("data", String))
Index("test_idx1", tbl.c.data, opengauss_with={"fillfactor": 50})
TABLESPACE
tbl = Table("testtbl", m, Column("data", String))
Index("test_idx1", tbl.c.data, opengauss_tablespace="sometablespace")
WHERE
, unsupported for index on a partitioned tabletbl = Table("testtbl", m, Column("data", Integer))
Index(
"test_idx1",
tbl.c.data,
opengauss_where=and_(tbl.c.data > 5, tbl.c.data < 10),
)
WITH ({storage_parameter = value})
Table("some_table", ..., opengauss_with={"storage_parameter": "value"})
ON COMMIT
Table("some_talbe", ..., prefixes=["TEMPORARY"], opengauss_on_commit="PRESERVE ROWS")
COMPRESS
Table("some_talbe", ..., opengauss_with={"ORIENTATION": "COLUMN"}, opengauss_compress=True)
TABLESPACE tablespace_name
Table("some_talbe", ..., opengauss_tablespace="tablespace_name")
PARTITION BY
Table("some_talbe", ..., opengauss_partition_by="RANGE(column_name) "
"(PARTITION P1 VALUES LESS THAN(10), "
"PARTITION P2 VALUES LESS THAN(MAXVALUE))")
ENABLE ROW MOVEMENT
Table("some_talbe", ..., opengauss_partition_by="RANGE(column_name) ...",
opengauss_enable_row_movement=True)
CONCURRENTLY
tbl = Table("testtbl", m, Column("data", Integer))
Index("test_idx1", tbl.c.data, opengauss_concurrently=True)
DISTRIBUTE BY
Table("some_table", ..., opengauss_distribute_by="HASH(column_name)")
NOTE: table without distributable columns will be set with "DISTRIBUTE BY REPLICATION"
TO GROUP
Table("some_table", ..., opengauss_to="GROUP group_name")
>>> python -m pip install wheel
>>> python setup.py bdist_wheel
export LD_LIBRARY_PATH=
and export PYTHONPATH=
to your path of package psycopg2
.tox -e py38
.>>> useradd omm -g dbgrp
>>> chown omm:dbgrp ${db_dir} -R
>>> su - omm
>>> sh install.sh -w ${db_password} -p 37200
>>> gs_ctl start -D ${db_dir}/data/single_node/
>>> gsql -d postgres -p 37200
openGauss=# create user scott identified by 'Tiger123';
openGauss=# create database test with owner=scott encoding='utf8' template=template0;
openGauss=# GRANT ALL PRIVILEGES TO scott;
openGauss=# ALTER DATABASE test SET default_text_search_config = 'pg_catalog.english';
openGauss=# \c test
test=# create schema test_schema AUTHORIZATION scott;
test=# create schema test_schema_2 AUTHORIZATION scott;
test=# \q
>>> gs_guc set -D ${db_dir}/data/single_node/ -c "ssl=off"
>>> gs_guc set -D ${db_dir}/data/single_node/ -c "max_prepared_transactions = 100"
>>> gs_guc reload -D ${db_dir}/data/single_node/ -h "local all scott sha256"
>>> gs_guc reload -D ${db_dir}/data/single_node/ -h "host all scott 127.0.0.1/32 sha256"
>>> gs_guc reload -D ${db_dir}/data/single_node/ -h "host all scott 0.0.0.0/0 sha256"
>>> gs_ctl stop -D ${db_dir}/data/single_node/
>>> gs_tl start -D ${db_dir}/data/single_node/
>>> gs_guc set -D ${db_dir}/data/single_node/ -c "log_min_error_statement = error"
>>> gs_guc set -D ${db_dir}/data/single_node/ -c "log_statement = 'all'"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。