Merge branch 'master' into 2master

This commit is contained in:
Helmut Merz 2024-03-09 20:58:38 +01:00
commit cbbc8a3b87

View file

@ -9,40 +9,6 @@ from sqlalchemy.dialects.sqlite import JSON
import threading import threading
class StorageFactory(object):
def sessionFactory(self):
return self.engine.connect
@staticmethod
def getEngine(dbtype, dbname, user, pw, host='localhost', port=5432, **kw):
return create_engine('%s:///%s' % (dbtype, dbname), **kw)
@staticmethod
def mark_changed(session):
pass
@staticmethod
def commit(conn):
conn.commit()
IdType = Integer
JsonType = JSON
def __init__(self, config):
self.engine = self.getEngine(config.dbengine, config.dbname,
config.dbuser, config.dbpassword)
self.Session = self.sessionFactory()
def __call__(self, schema=None):
return Storage(self, schema=schema)
# you may put something like this in your code:
#factory = StorageFactory(config)
# and then call at appropriate places:
#storage = scopes.storage.common.factory(schema=...)
class Storage(object): class Storage(object):
def __init__(self, db, schema=None): def __init__(self, db, schema=None):
@ -93,6 +59,36 @@ class Storage(object):
conn.execute(text(sq)) conn.execute(text(sq))
class StorageFactory(object):
def sessionFactory(self):
return self.engine.connect
@staticmethod
def getEngine(dbtype, dbname, user, pw, host='localhost', port=5432, **kw):
return create_engine('%s:///%s' % (dbtype, dbname), **kw)
@staticmethod
def mark_changed(session):
pass
@staticmethod
def commit(conn):
conn.commit()
IdType = Integer
JsonType = JSON
def __init__(self, config, storageClass=Storage):
self.engine = self.getEngine(config.dbengine, config.dbname,
config.dbuser, config.dbpassword)
self.Session = self.sessionFactory()
self.storageClass = storageClass
def __call__(self, schema=None):
return self.storageClass(self, schema=schema)
# store information about container implementations, identified by a uid prefix. # store information about container implementations, identified by a uid prefix.
registry = {} registry = {}