This commit is contained in:
yumoqing 2023-03-13 10:44:08 +08:00
parent 009fb014cd
commit 4bac4349bf
6 changed files with 13 additions and 15 deletions

0
databases.json Normal file → Executable file
View File

0
docs/postgresql.md Normal file → Executable file
View File

0
sqlor/aiosqliteor.py Normal file → Executable file
View File

View File

@ -8,7 +8,6 @@ import codecs
import re import re
import json import json
from appPublic.myImport import myImport from appPublic.myImport import myImport
from appPublic.dictObject import DictObject,dictObjectFactory
from appPublic.unicoding import uDict from appPublic.unicoding import uDict
from appPublic.myTE import MyTemplateEngine from appPublic.myTE import MyTemplateEngine
from appPublic.objectAction import ObjectAction from appPublic.objectAction import ObjectAction
@ -283,7 +282,7 @@ class SQLor(object):
dic = {} dic = {}
for i in range(len(fields)): for i in range(len(fields)):
dic.update({fields[i] : db_type_2_py_type(rec[i])}) dic.update({fields[i] : db_type_2_py_type(rec[i])})
callback(DictObject(**dic),**kwargs) callback(dic,**kwargs)
if self.async_mode: if self.async_mode:
rec = await cur.fetchone() rec = await cur.fetchone()
else: else:
@ -389,7 +388,7 @@ class SQLor(object):
"total":total, "total":total,
"rows":recs "rows":recs
} }
return DictObject(**data) return data
async def pagingdata(self,desc,NS): async def pagingdata(self,desc,NS):
paging_desc = {} paging_desc = {}
@ -424,7 +423,7 @@ class SQLor(object):
async def resultFields(self,desc,NS): async def resultFields(self,desc,NS):
NS.update(rows=1,page=1) NS.update(rows=1,page=1)
r = await self.pagingdata(desc,NS) r = await self.pagingdata(desc,NS)
ret = [ DictObject(**{'name':i[0],'type':i[1]}) for i in self.cur.description ] ret = [ {'name':i[0],'type':i[1]} for i in self.cur.description ]
return ret return ret
async def runSQL(self,desc,NS,callback,**kw): async def runSQL(self,desc,NS,callback,**kw):
@ -435,8 +434,7 @@ class SQLor(object):
self.ns[name] = [] self.ns[name] = []
def handler(self,rec): def handler(self,rec):
obj = DictObject(**rec) self.ns[self.name].append(rec)
self.ns[self.name].append(obj)
cur = self.cursor() cur = self.cursor()
sql = self.getSQLfromDesc(desc) sql = self.getSQLfromDesc(desc)
@ -456,7 +454,7 @@ class SQLor(object):
async def sqlExe(self,sql,ns): async def sqlExe(self,sql,ns):
ret = [] ret = []
await self.execute(sql,ns, await self.execute(sql,ns,
callback=lambda x:ret.append(DictObject(**x))) callback=lambda x:ret.append(x))
return ret return ret
async def tables(self): async def tables(self):
@ -519,9 +517,9 @@ class SQLor(object):
if desc: if desc:
return desc return desc
desc = {} desc = {}
summary = [ i.to_dict() for i in await self.tables() if tablename.lower() == i.name.lower() ] summary = [ i for i in await self.tables() if tablename.lower() == i['name'].lower() ]
pris = await self.primary(tablename) pris = await self.primary(tablename)
primary = [i.name for i in pris ] primary = [i['name'] for i in pris ]
summary[0]['primary'] = primary summary[0]['primary'] = primary
desc['summary'] = summary desc['summary'] = summary
desc['fields'] = await self.fields(tablename=tablename) desc['fields'] = await self.fields(tablename=tablename)
@ -529,17 +527,17 @@ class SQLor(object):
idx = {} idx = {}
idxrecs = await self.indexes(tablename) idxrecs = await self.indexes(tablename)
for idxrec in idxrecs: for idxrec in idxrecs:
if idxrec.index_name == 'primary': if idxrec['index_name'] == 'primary':
continue continue
if idxrec.index_name != idx.get('name',None): if idxrec['index_name'] != idx.get('name',None):
if idx != {}: if idx != {}:
desc['indexes'].append(idx) desc['indexes'].append(idx)
idx = { idx = {
} }
idx['name'] = idxrec.index_name idx['name'] = idxrec['index_name']
idx['idxtype'] = 'unique' if idxrec.is_unique else 'index' idx['idxtype'] = 'unique' if idxrec['is_unique'] else 'index'
idx['idxfields'] = [] idx['idxfields'] = []
idx['idxfields'].append(idxrec.column_name) idx['idxfields'].append(idxrec['column_name'])
if idx != {}: if idx != {}:
desc['indexes'].append(idx) desc['indexes'].append(idx)
self.setMeta(tablename,desc) self.setMeta(tablename,desc)

0
sqlor/version.py Normal file → Executable file
View File

0
test/sqlite3_sql.py Normal file → Executable file
View File