... and back to PostgreSQL
This commit is contained in:
		
							parent
							
								
									592e653561
								
							
						
					
					
						commit
						dba278fc02
					
				
					 4 changed files with 21 additions and 12 deletions
				
			
		|  | @ -5,20 +5,22 @@ build-backend = "setuptools.build_meta" | ||||||
| [project] | [project] | ||||||
| name = "py-scopes" | name = "py-scopes" | ||||||
| version = "3.0.1" | version = "3.0.1" | ||||||
| description = "Implementation of the strange 'scopes' paradigma in Python" | description = "Implementation of the unknown 'scopes' paradigm in Python" | ||||||
| readme = "README.md" | readme = "README.md" | ||||||
| license = {text = "MIT"} | license = {text = "MIT"} | ||||||
| keywords = ["scopes"] | keywords = ["scopes"] | ||||||
| authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}] | authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}] | ||||||
| 
 | 
 | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  | ] | ||||||
|  | 
 | ||||||
|  | [project.optional-dependencies] | ||||||
|  | postgres = [ | ||||||
| 	"transaction", | 	"transaction", | ||||||
| 	"psycopg[binary]", | 	"psycopg[binary]", | ||||||
| 	"SQLAlchemy", | 	"SQLAlchemy", | ||||||
| 	"zope.sqlalchemy", | 	"zope.sqlalchemy", | ||||||
| ] | ] | ||||||
| 
 |  | ||||||
| [project.optional-dependencies] |  | ||||||
| app = ["python-dotenv", "zope.publisher", "zope.traversing"] | app = ["python-dotenv", "zope.publisher", "zope.traversing"] | ||||||
| test = ["pytest"] | test = ["pytest"] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ | ||||||
| """Database-related code specific for PostgreSQL.""" | """Database-related code specific for PostgreSQL.""" | ||||||
| 
 | 
 | ||||||
| from sqlalchemy import create_engine | from sqlalchemy import create_engine | ||||||
| from sqlalchemy import BigInteger, JSONB | from sqlalchemy import BigInteger | ||||||
| from sqlalchemy.dialects.postgresql import JSONB | from sqlalchemy.dialects.postgresql import JSONB | ||||||
| from sqlalchemy.orm import scoped_session, sessionmaker | from sqlalchemy.orm import scoped_session, sessionmaker | ||||||
| import transaction | import transaction | ||||||
|  | @ -21,3 +21,12 @@ def getEngine(dbtype, dbname, user, pw, host='localhost', port=5432, **kw): | ||||||
| 
 | 
 | ||||||
| def commit(conn): | def commit(conn): | ||||||
|     transaction.commit() |     transaction.commit() | ||||||
|  | 
 | ||||||
|  | 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 | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ app = zope_app | ||||||
| # storage settings | # storage settings | ||||||
| 
 | 
 | ||||||
| # PostgreSQL | # PostgreSQL | ||||||
|  | import scopes.storage.db.postgres | ||||||
| dbengine = 'postgresql+psycopg' | dbengine = 'postgresql+psycopg' | ||||||
| dbname = 'testdb' | dbname = 'testdb' | ||||||
| dbuser = 'testuser' | dbuser = 'testuser' | ||||||
|  | @ -16,7 +17,7 @@ dbpassword = 'secret' | ||||||
| dbschema = 'testing' | dbschema = 'testing' | ||||||
| 
 | 
 | ||||||
| # SQLite | # SQLite | ||||||
| dbengine = 'sqlite' | #dbengine = 'sqlite' | ||||||
| dbname = 'var/test.db' | #dbname = 'var/test.db' | ||||||
| dbschema = None | #dbschema = None | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,9 +17,7 @@ engine = getEngine(config.dbengine, config.dbname, config.dbuser, config.dbpassw | ||||||
| scopes.storage.common.engine = engine | scopes.storage.common.engine = engine | ||||||
| scopes.storage.common.Session = sessionFactory(engine) | scopes.storage.common.Session = sessionFactory(engine) | ||||||
| 
 | 
 | ||||||
| #storage = Storage(schema='testing') | storage = Storage(schema=config.dbschema) | ||||||
| #storage = Storage(schema=config.dbschema) |  | ||||||
| storage = Storage() |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Test(unittest.TestCase): | class Test(unittest.TestCase): | ||||||
|  | @ -86,8 +84,7 @@ class Test(unittest.TestCase): | ||||||
|         self.assertEqual(ch1.parent, top.rid) |         self.assertEqual(ch1.parent, top.rid) | ||||||
|         assert list(top.keys()) == ['child1'] |         assert list(top.keys()) == ['child1'] | ||||||
| 
 | 
 | ||||||
|         #transaction.commit() |         commit(storage.session) | ||||||
|         storage.session.commit() |  | ||||||
| 
 | 
 | ||||||
| def suite(): | def suite(): | ||||||
|     return unittest.TestSuite(( |     return unittest.TestSuite(( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue