This commit is contained in:
yumoqing 2025-10-20 11:48:58 +08:00
parent 92f2857ce6
commit be7faa09ed
6 changed files with 90 additions and 12 deletions

View File

@ -14,15 +14,73 @@ SQLOR is a database api for python3, it is base on the python's DBAPI2
## requirements ## requirements
* python 3.5 or above * python 3.9 or above
* asyncio * asyncio
* Oracle DBAPI2 driver(cx_Oracle) * Oracle DBAPI2 driver(cx_Oracle)
* MySQL DBAPI2 driver(mysql-connector) * Postgresql DBAPI2 driver(aiopg)
* Postgresql DBAPI2 driver(psycopg2-binrary)
* Asynchronous MySQL driver(aiomysql) * Asynchronous MySQL driver(aiomysql)
* Asynchronous Postgresql driver(aiopg) * Asynchronous Postgresql driver(aiopg)
* clickhouse(clickhouse-connect)
* Other driver can be easy integreated * 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 ## Using
``` ```
@ -31,11 +89,8 @@ import asyncio
from sqlor.dbpools import DBPools, sqlorContext from sqlor.dbpools import DBPools, sqlorContext
dbs={ dbs={
"aiocfae":{ "mydb":{
"driver":"aiomysql", "driver":"mysql",
"async_mode":True,
"coding":"utf8",
"dbname":"cfae",
"kwargs":{ "kwargs":{
"user":"test", "user":"test",
"db":"cfae", "db":"cfae",

View File

@ -12,8 +12,9 @@ packages = find:
requires_python = >=3.8 requires_python = >=3.8
install_requires = install_requires =
aiomysql aiomysql
aiopg
duckdb duckdb
clickhouse-connect clickhouse-driver
PyMySQL PyMySQL
aiosqlite aiosqlite
asyncio asyncio

View File

@ -1,4 +1,6 @@
# -*- coding:utf8 -*- # -*- coding:utf8 -*-
# pip install clickhouse-driver
from clickhouse_driver import Client
from appPublic.argsConvert import ArgsConvert, ConditionConvert from appPublic.argsConvert import ArgsConvert, ConditionConvert
from .sor import SQLor from .sor import SQLor
from .ddl_template_clickhouse import clickhouse_ddl_tmpl 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 不支持外键 # ClickHouse 不支持外键
return "SELECT 'ClickHouse does not support foreign keys' AS msg;" 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()

View File

@ -21,7 +21,6 @@ from .oracleor import Oracleor
from .sqlite3or import SQLite3or from .sqlite3or import SQLite3or
from .aiosqliteor import Aiosqliteor from .aiosqliteor import Aiosqliteor
from .mysqlor import MySqlor from .mysqlor import MySqlor
from .aiomysqlor import AioMysqlor
from .aiopostgresqlor import AioPostgresqlor from .aiopostgresqlor import AioPostgresqlor
def sqlorFactory(dbdesc): def sqlorFactory(dbdesc):

View File

@ -1,4 +1,5 @@
# -*- coding:utf8 -*- # -*- coding:utf8 -*-
import duckdb
from appPublic.argsConvert import ArgsConvert, ConditionConvert from appPublic.argsConvert import ArgsConvert, ConditionConvert
from .sor import SQLor from .sor import SQLor
from .const import ROWS from .const import ROWS
@ -117,3 +118,15 @@ class DuckDBor(SQLor):
sqlcmd += f" AND lower(table_name) = '{tablename.lower()}'" sqlcmd += f" AND lower(table_name) = '{tablename.lower()}'"
return sqlcmd 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

View File

@ -90,8 +90,9 @@ class SQLor(object):
self.metadatas={} self.metadatas={}
def unpassword(self): def unpassword(self):
key=getConfig().password_key if self.dbdesc.password:
self.dbdesc.password = aes_decode_b64(key, self.dbdesc.password) key=getConfig().password_key
self.dbdesc.password = aes_decode_b64(key, self.dbdesc.password)
async def get_schema(self): async def get_schema(self):
def concat_idx_info(idxs): def concat_idx_info(idxs):