bug fix: readonly for duckdb

This commit is contained in:
Steve Nyemba 2025-02-19 23:03:14 -06:00
parent cdf783143e
commit 30645e46bd
2 changed files with 12 additions and 4 deletions

View File

@ -13,7 +13,13 @@ class Base:
self._port = None
self._database = _args['database']
self._table = _args['table'] if 'table' in _args else None
self._engine= sqa.create_engine(self._get_uri(**_args),future=True)
_uri = self._get_uri(**_args)
if type(_uri) == str :
self._engine= sqa.create_engine(_uri,future=True)
else:
_uri,_kwargs = _uri
self._engine= sqa.create_engine(_uri,**_kwargs,future=True)
def _set_uri(self,**_args) :
"""
:provider provider
@ -64,8 +70,8 @@ class Base:
@TODO: Execution of stored procedures
"""
if sql.lower().startswith('select') or sql.lower().startswith('with') :
if sql.strip().lower().startswith('select') or sql.strip().lower().startswith('with') or sql.strip().startswith('show'):
print (self._engine)
return pd.read_sql(sql,self._engine)
else:
_handler = self._engine.connect()

View File

@ -18,6 +18,8 @@ class Reader(Duck,BaseReader) :
def __init__(self,**_args):
Duck.__init__(self,**_args)
BaseReader.__init__(self,**_args)
def _get_uri(self,**_args):
return super()._get_uri(**_args),{'connect_args':{'read_only':True}}
class Writer(Duck,BaseWriter):
def __init__(self,**_args):
Duck.__init__(self,**_args)