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
* 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",

View File

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

View File

@ -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()

View File

@ -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):

View File

@ -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

View File

@ -90,6 +90,7 @@ class SQLor(object):
self.metadatas={}
def unpassword(self):
if self.dbdesc.password:
key=getConfig().password_key
self.dbdesc.password = aes_decode_b64(key, self.dbdesc.password)