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 | ||||
| JsonType = JSON | ||||
| 
 | ||||
| # put something like this in code before first creating a Storage object | ||||
| #engine = getEngine('postgresql+psycopg', 'testdb', 'testuser', 'secret') | ||||
| #scopes.storage.common.engine = engine | ||||
| #scopes.storage.common.Session = sessionFactory(engine) | ||||
| 
 | ||||
| class StorageFactory(object): | ||||
| 
 | ||||
|     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): | ||||
|  |  | |||
|  | @ -24,10 +24,11 @@ def commit(conn): | |||
| 
 | ||||
| # patch `common` module | ||||
| import scopes.storage.common | ||||
| scopes.storage.common.IdType = BigInteger | ||||
| scopes.storage.common.JsonType = JSONB | ||||
| scopes.storage.common.sessionFactory = sessionFactory | ||||
| scopes.storage.common.getEngine = getEngine | ||||
| scopes.storage.common.mark_changed = mark_changed | ||||
| scopes.storage.common.commit = commit | ||||
| def init(): | ||||
|     scopes.storage.common.IdType = BigInteger | ||||
|     scopes.storage.common.JsonType = JSONB | ||||
|     scopes.storage.common.sessionFactory = sessionFactory | ||||
|     scopes.storage.common.getEngine = getEngine | ||||
|     scopes.storage.common.mark_changed = mark_changed | ||||
|     scopes.storage.common.commit = commit | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,11 +2,8 @@ | |||
| 
 | ||||
| """Tests for the 'scopes.storage' package - using PostgreSQL.""" | ||||
| 
 | ||||
| from datetime import datetime | ||||
| import unittest | ||||
| 
 | ||||
| # PostgreSQL-specific settings | ||||
| import scopes.storage.db.postgres | ||||
| import config | ||||
| config.dbengine = 'postgresql+psycopg' | ||||
| config.dbname = 'testdb' | ||||
|  | @ -14,7 +11,14 @@ config.dbuser = 'testuser' | |||
| config.dbpassword = 'secret' | ||||
| config.dbschema = 'testing' | ||||
| 
 | ||||
| # PostgreSQL-specific settings | ||||
| from scopes.storage.db import postgres  | ||||
| postgres.init() | ||||
| 
 | ||||
| import tlib | ||||
| tlib.init(config) | ||||
| #factory = postgres.StorageFactory(config) | ||||
| #storage = factory(schema='testing') | ||||
| 
 | ||||
| class Test(unittest.TestCase): | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,10 +2,14 @@ | |||
| 
 | ||||
| """Tests for the 'scopes.storage' package.""" | ||||
| 
 | ||||
| from datetime import datetime | ||||
| import unittest | ||||
| 
 | ||||
| import config | ||||
| import tlib | ||||
| tlib.init(config) | ||||
| #from scopes.storage.common import StorageFactory | ||||
| #factory = StorageFactory(config) | ||||
| #storage = factory(schema=None) | ||||
| 
 | ||||
| class Test(unittest.TestCase): | ||||
| 
 | ||||
|  | @ -1,17 +1,17 @@ | |||
| """The real test implementations""" | ||||
| 
 | ||||
| import config | ||||
| from datetime import datetime | ||||
| from scopes.storage import folder, tracking | ||||
| 
 | ||||
| import scopes.storage.common | ||||
| from scopes.storage.common import commit, Storage, getEngine, sessionFactory | ||||
| 
 | ||||
| engine = getEngine(config.dbengine, config.dbname, config.dbuser, config.dbpassword)  | ||||
| scopes.storage.common.engine = engine | ||||
| scopes.storage.common.Session = sessionFactory(engine) | ||||
| 
 | ||||
| storage = Storage(schema=config.dbschema) | ||||
| def init(config): | ||||
|     global storage | ||||
|     engine = getEngine(config.dbengine, config.dbname, config.dbuser, config.dbpassword)  | ||||
|     scopes.storage.common.engine = engine | ||||
|     scopes.storage.common.Session = sessionFactory(engine) | ||||
|     storage = Storage(schema=config.dbschema) | ||||
| 
 | ||||
| 
 | ||||
| def test_tracking(self): | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue