work in progress: separate settings for different types of databases
This commit is contained in:
parent
23f9b1c384
commit
fbe8d99d74
5 changed files with 52 additions and 20 deletions
|
@ -27,10 +27,33 @@ def commit(conn):
|
||||||
IdType = Integer
|
IdType = Integer
|
||||||
JsonType = JSON
|
JsonType = JSON
|
||||||
|
|
||||||
# put something like this in code before first creating a Storage object
|
|
||||||
#engine = getEngine('postgresql+psycopg', 'testdb', 'testuser', 'secret')
|
class StorageFactory(object):
|
||||||
#scopes.storage.common.engine = engine
|
|
||||||
#scopes.storage.common.Session = sessionFactory(engine)
|
engine = Session = None
|
||||||
|
|
||||||
|
sessionFactory = sessionFactory
|
||||||
|
getEngine = getEngine
|
||||||
|
mark_changed = mark_changed
|
||||||
|
commit = commit
|
||||||
|
IdType = IdType
|
||||||
|
JsonType = JsonType
|
||||||
|
|
||||||
|
def __call__(self, schema=None):
|
||||||
|
st = Storage(schema=schema)
|
||||||
|
st.setup(self)
|
||||||
|
return st
|
||||||
|
|
||||||
|
def setup(self, config):
|
||||||
|
self.engine = self.getEngine(config.dbengine, config.dbname,
|
||||||
|
config.dbuser, config.dbpassword)
|
||||||
|
self.Session = self.sessionFactory
|
||||||
|
|
||||||
|
|
||||||
|
# you may put something like this in your code:
|
||||||
|
#scopes.storage.common.factory = StorageFactory(config)
|
||||||
|
# and then call at appropriate places:
|
||||||
|
#storage = scopes.storage.common.factory(schema=...)
|
||||||
|
|
||||||
|
|
||||||
class Storage(object):
|
class Storage(object):
|
||||||
|
|
|
@ -24,10 +24,11 @@ def commit(conn):
|
||||||
|
|
||||||
# patch `common` module
|
# patch `common` module
|
||||||
import scopes.storage.common
|
import scopes.storage.common
|
||||||
scopes.storage.common.IdType = BigInteger
|
def init():
|
||||||
scopes.storage.common.JsonType = JSONB
|
scopes.storage.common.IdType = BigInteger
|
||||||
scopes.storage.common.sessionFactory = sessionFactory
|
scopes.storage.common.JsonType = JSONB
|
||||||
scopes.storage.common.getEngine = getEngine
|
scopes.storage.common.sessionFactory = sessionFactory
|
||||||
scopes.storage.common.mark_changed = mark_changed
|
scopes.storage.common.getEngine = getEngine
|
||||||
scopes.storage.common.commit = commit
|
scopes.storage.common.mark_changed = mark_changed
|
||||||
|
scopes.storage.common.commit = commit
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,8 @@
|
||||||
|
|
||||||
"""Tests for the 'scopes.storage' package - using PostgreSQL."""
|
"""Tests for the 'scopes.storage' package - using PostgreSQL."""
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
# PostgreSQL-specific settings
|
|
||||||
import scopes.storage.db.postgres
|
|
||||||
import config
|
import config
|
||||||
config.dbengine = 'postgresql+psycopg'
|
config.dbengine = 'postgresql+psycopg'
|
||||||
config.dbname = 'testdb'
|
config.dbname = 'testdb'
|
||||||
|
@ -14,7 +11,14 @@ config.dbuser = 'testuser'
|
||||||
config.dbpassword = 'secret'
|
config.dbpassword = 'secret'
|
||||||
config.dbschema = 'testing'
|
config.dbschema = 'testing'
|
||||||
|
|
||||||
|
# PostgreSQL-specific settings
|
||||||
|
from scopes.storage.db import postgres
|
||||||
|
postgres.init()
|
||||||
|
|
||||||
import tlib
|
import tlib
|
||||||
|
tlib.init(config)
|
||||||
|
#factory = postgres.StorageFactory(config)
|
||||||
|
#storage = factory(schema='testing')
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
|
|
||||||
"""Tests for the 'scopes.storage' package."""
|
"""Tests for the 'scopes.storage' package."""
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import config
|
||||||
import tlib
|
import tlib
|
||||||
|
tlib.init(config)
|
||||||
|
#from scopes.storage.common import StorageFactory
|
||||||
|
#factory = StorageFactory(config)
|
||||||
|
#storage = factory(schema=None)
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
"""The real test implementations"""
|
"""The real test implementations"""
|
||||||
|
|
||||||
import config
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from scopes.storage import folder, tracking
|
from scopes.storage import folder, tracking
|
||||||
|
|
||||||
import scopes.storage.common
|
import scopes.storage.common
|
||||||
from scopes.storage.common import commit, Storage, getEngine, sessionFactory
|
from scopes.storage.common import commit, Storage, getEngine, sessionFactory
|
||||||
|
|
||||||
engine = getEngine(config.dbengine, config.dbname, config.dbuser, config.dbpassword)
|
def init(config):
|
||||||
scopes.storage.common.engine = engine
|
global storage
|
||||||
scopes.storage.common.Session = sessionFactory(engine)
|
engine = getEngine(config.dbengine, config.dbname, config.dbuser, config.dbpassword)
|
||||||
|
scopes.storage.common.engine = engine
|
||||||
storage = Storage(schema=config.dbschema)
|
scopes.storage.common.Session = sessionFactory(engine)
|
||||||
|
storage = Storage(schema=config.dbschema)
|
||||||
|
|
||||||
|
|
||||||
def test_tracking(self):
|
def test_tracking(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue