From be7faa09ed8c88e959adbad95bf7fa64a9598298 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 20 Oct 2025 11:48:58 +0800 Subject: [PATCH] bugfix --- README.md | 71 ++++++++++++++++++++++++++++++++++++++----- setup.cfg | 3 +- sqlor/clickhouseor.py | 9 ++++++ sqlor/dbpools.py | 1 - sqlor/duckdbor.py | 13 ++++++++ sqlor/sor.py | 5 +-- 6 files changed, 90 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4cc2a46..7f720fc 100755 --- a/README.md +++ b/README.md @@ -14,15 +14,73 @@ SQLOR is a database api for python3, it is base on the python's DBAPI2 ## requirements -* python 3.5 or above +* python 3.9 or above * asyncio * Oracle DBAPI2 driver(cx_Oracle) -* MySQL DBAPI2 driver(mysql-connector) -* Postgresql DBAPI2 driver(psycopg2-binrary) +* Postgresql DBAPI2 driver(aiopg) * Asynchronous MySQL driver(aiomysql) * Asynchronous Postgresql driver(aiopg) +* clickhouse(clickhouse-connect) * Other driver can be easy integreated +## Support Database Types +* oracle +* mysql, mariadb +* TiDB +* clickHouse +* DuckDB +* PostgreSQL +* MsSQL + +## Database Description json format +password in json data is encrypted by aes. + +* mysql, tidb, mariadb +``` +{ + "databases":{ + "mydb":{ + "driver":"mysql", + "kwargs":{ + "user":"test", + "db":"cfae", + "password":"test123", + "host":"localhost" + } + } + } +} +``` +* PostgreSQL +``` +{ + "databases":{ + "mydb":{ + "driver":"postgresql", + "kwargs":{ + "user":"test", + "dbname":"cfae", + "password":"test123", + "host":"localhost" + } + } + } +} +``` +* duckdb +``` +{ + "databases":{ + "mydb":{ + "driver":"duckdb", + "kwargs":{ + "dbfile":"ttt.ddb" + } + } + } +} +``` + ## Using ``` @@ -31,11 +89,8 @@ import asyncio from sqlor.dbpools import DBPools, sqlorContext dbs={ - "aiocfae":{ - "driver":"aiomysql", - "async_mode":True, - "coding":"utf8", - "dbname":"cfae", + "mydb":{ + "driver":"mysql", "kwargs":{ "user":"test", "db":"cfae", diff --git a/setup.cfg b/setup.cfg index 2ff9da5..1656531 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,8 +12,9 @@ packages = find: requires_python = >=3.8 install_requires = aiomysql + aiopg duckdb - clickhouse-connect + clickhouse-driver PyMySQL aiosqlite asyncio diff --git a/sqlor/clickhouseor.py b/sqlor/clickhouseor.py index b5c0e9b..3e6aecf 100644 --- a/sqlor/clickhouseor.py +++ b/sqlor/clickhouseor.py @@ -1,4 +1,6 @@ # -*- coding:utf8 -*- +# pip install clickhouse-driver +from clickhouse_driver import Client from appPublic.argsConvert import ArgsConvert, ConditionConvert from .sor import SQLor from .ddl_template_clickhouse import clickhouse_ddl_tmpl @@ -95,3 +97,10 @@ WHERE database = '%s' AND table = '%s' AND is_in_primary_key = 1; # ClickHouse 不支持外键 return "SELECT 'ClickHouse does not support foreign keys' AS msg;" + async def connect(self): + self.conn = Client(**self.dbdesc) + self.cur = self.conn + + async def close(self): + self.conn.close() + diff --git a/sqlor/dbpools.py b/sqlor/dbpools.py index 1224d03..25f9514 100755 --- a/sqlor/dbpools.py +++ b/sqlor/dbpools.py @@ -21,7 +21,6 @@ from .oracleor import Oracleor from .sqlite3or import SQLite3or from .aiosqliteor import Aiosqliteor from .mysqlor import MySqlor -from .aiomysqlor import AioMysqlor from .aiopostgresqlor import AioPostgresqlor def sqlorFactory(dbdesc): diff --git a/sqlor/duckdbor.py b/sqlor/duckdbor.py index 0672f03..15925f8 100644 --- a/sqlor/duckdbor.py +++ b/sqlor/duckdbor.py @@ -1,4 +1,5 @@ # -*- coding:utf8 -*- +import duckdb from appPublic.argsConvert import ArgsConvert, ConditionConvert from .sor import SQLor from .const import ROWS @@ -117,3 +118,15 @@ class DuckDBor(SQLor): sqlcmd += f" AND lower(table_name) = '{tablename.lower()}'" return sqlcmd + async def connect(self): + self.conn = duckdb.connect(self.dbdesc.dbfile) + self.cur = self.conn + self.dbname = None + + async def close(self): + self.conn.close() + + def unpassword(self): + pass + + diff --git a/sqlor/sor.py b/sqlor/sor.py index 8c8743e..590bbfd 100755 --- a/sqlor/sor.py +++ b/sqlor/sor.py @@ -90,8 +90,9 @@ class SQLor(object): self.metadatas={} def unpassword(self): - key=getConfig().password_key - self.dbdesc.password = aes_decode_b64(key, self.dbdesc.password) + if self.dbdesc.password: + key=getConfig().password_key + self.dbdesc.password = aes_decode_b64(key, self.dbdesc.password) async def get_schema(self): def concat_idx_info(idxs):