add sqlor context
This commit is contained in:
parent
eec5507b5d
commit
a18b9c381c
@ -2,6 +2,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import codecs
|
import codecs
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
from appPublic.myImport import myImport
|
from appPublic.myImport import myImport
|
||||||
from appPublic.dictObject import DictObject
|
from appPublic.dictObject import DictObject
|
||||||
@ -186,6 +187,14 @@ class DBPools:
|
|||||||
async def freeSqlor(self,sor):
|
async def freeSqlor(self,sor):
|
||||||
await self._releaseConn(sor.name,sor.conn,sor.cur)
|
await self._releaseConn(sor.name,sor.conn,sor.cur)
|
||||||
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def sqlorContext(self,name):
|
||||||
|
sqlor = await self.getSqlor(name)
|
||||||
|
try:
|
||||||
|
yield sqlor
|
||||||
|
finally:
|
||||||
|
await self.freeSqlor(sqlor)
|
||||||
|
|
||||||
async def _aquireConn(self,dbname):
|
async def _aquireConn(self,dbname):
|
||||||
p = self._cpools.get(dbname)
|
p = self._cpools.get(dbname)
|
||||||
if p == None:
|
if p == None:
|
||||||
|
@ -456,4 +456,3 @@ class SQLor(object):
|
|||||||
return desc
|
return desc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user