add records.py

This commit is contained in:
yumoqing 2019-05-23 16:28:36 +08:00
parent 3b24b1f6ab
commit 7a3a3836bb
3 changed files with 40 additions and 4 deletions

View File

@ -12,6 +12,7 @@ sqlor/mssqlor.py
sqlor/mysqlor.py
sqlor/oracleor.py
sqlor/postgresqlor.py
sqlor/records.py
sqlor/sor.py
sqlor/sqlite3or.py
sqlor.egg-info/PKG-INFO

27
sqlor/records.py Normal file
View File

@ -0,0 +1,27 @@
from appPublic.dictObject import DictObject
class Records:
def __init__(self,klass=DictObject):
self._records = []
self.klass = klass
def add(self,rec):
obj = self.klass(**rec)
self._records.append(obj)
def get(self):
return self._records
def __iter__(self):
self.start = 0
self.end = len(self._records)
return self
def __next__(self):
if self.start < self.end:
d = self._records[self.start]
self.start = self.start + 1
return d
else:
raise StopIteration

View File

@ -1,6 +1,7 @@
import asyncio
from sqlor.dbpools import DBPools
from sqlor.records import Records
dbs={
"aiocfae":{
@ -37,16 +38,23 @@ async def testfunc1():
return {
"sql_string":"select * from product",
}
x = await sql('cfae',{},print)
recs = Records()
x = await sql('cfae',{},recs.add)
print('--------------%s---------------' % x)
for r in recs:
print(type(r),r)
async def testfunc2():
@pool.runSQLResultFields
def sql(db,NS):
def sql(db,ns,callback=None):
return {
"sql_string":"select * from product",
}
x = await sql('cfae',{})
print(x)
recs = Records()
x = await sql('cfae',{},callback=recs.add)
print('-------%s------' % x)
for i in recs._records:
print("--",i)
loop.run_until_complete(testfunc1())
loop.run_until_complete(testfunc2())