diff --git a/sqlor.egg-info/SOURCES.txt b/sqlor.egg-info/SOURCES.txt index 6c43cc3..0b3c833 100644 --- a/sqlor.egg-info/SOURCES.txt +++ b/sqlor.egg-info/SOURCES.txt @@ -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 diff --git a/sqlor/records.py b/sqlor/records.py new file mode 100644 index 0000000..f52b026 --- /dev/null +++ b/sqlor/records.py @@ -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 diff --git a/test/test.py b/test/test.py index 2a093de..5cf717f 100644 --- a/test/test.py +++ b/test/test.py @@ -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())