Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Installation from PyPI:
pip install gaussdb-pool
python -c "import gaussdb; print(gaussdb.__version__)" # Outputs: 1.0.0.dev2

# Run demo
python ./example/demo.py

You can also clone this repository to develop GaussDB::

# Create a new Python virtual environment in the .venv directory
Expand Down Expand Up @@ -111,8 +114,8 @@ Please add ``--config-settings editable_mode=strict`` to the ``pip install

Now hack away! You can run the tests using on GaussDB::

# Create a new database named "test" with PostgreSQL compatibility enabled
gsql -c 'CREATE DATABASE test DBCOMPATIBILITY 'PG' ;'
# Create a new database named "test" with Default compatibility with Oracle enabled
gsql -c 'CREATE DATABASE test;'

# Set the Python import path to include your local GaussDB Python project
# Replace your_path with actual values
Expand Down Expand Up @@ -154,8 +157,8 @@ Recommended Steps to Run OpenGauss with Python GaussDB Driver Testing (Assuming
# Connect to the OpenGauss database using the gsql client
gsql -d postgres -p 5432 -U omm

-- Create a new database named "test" with PostgreSQL compatibility enabled
CREATE DATABASE test DBCOMPATIBILITY 'PG';
-- Create a new database named "test" with Default compatibility with Oracle enabled
CREATE DATABASE test;


# Set the Python import path to include your local GaussDB Python project
Expand Down
50 changes: 50 additions & 0 deletions example/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-

import os
import sys

from gaussdb import connect

os.environ["GAUSSDB_IMPL"] = "python"


def main():
dsn = os.environ.get("GAUSSDB_TEST_DSN")
if not dsn:
print("❌ Please set the GAUSSDB_TEST_DSN environment variable, for example:")
print(
' export GAUSSDB_TEST_DSN="dbname=test01 user=root password=***'
'host=** port=8000"'
)
sys.exit(1)

drop_table_sql = "DROP TABLE IF EXISTS test"
create_table_sql = (
"CREATE TABLE test (id serial PRIMARY KEY, num integer, data text)"
)
insert_data_sql = "INSERT INTO test (num, data) VALUES (%s, %s)"
update_data_sql = "UPDATE test SET data = 'gaussdb' WHERE num = 2"
select_sql = "SELECT * FROM test"

with connect(dsn, connect_timeout=10, application_name="gaussdb-demo") as conn:

with conn.cursor() as cur:
server_version = conn.execute("select version()").fetchall()[0][0]
print(f"✅ Connected. Server version: {server_version}")
print(f"Vendor: {conn.info.vendor}, Version: {conn.info.server_version}")

cur.execute(drop_table_sql)
cur.execute(create_table_sql)
cur.execute(insert_data_sql, (1, "hello"))
cur.execute(insert_data_sql, (2, "world"))

cur.execute(select_sql)
print("📄origin: ", cur.fetchall())

cur.execute(update_data_sql)
cur.execute(select_sql)
print("📄update: ", cur.fetchall())


if __name__ == "__main__":
main()
Loading