... and back to PostgreSQL

This commit is contained in:
Helmut Merz 2024-03-07 09:02:59 +01:00
parent 592e653561
commit dba278fc02
4 changed files with 21 additions and 12 deletions

View file

@ -5,20 +5,22 @@ build-backend = "setuptools.build_meta"
[project]
name = "py-scopes"
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"
license = {text = "MIT"}
keywords = ["scopes"]
authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}]
dependencies = [
]
[project.optional-dependencies]
postgres = [
"transaction",
"psycopg[binary]",
"SQLAlchemy",
"zope.sqlalchemy",
]
[project.optional-dependencies]
app = ["python-dotenv", "zope.publisher", "zope.traversing"]
test = ["pytest"]

View file

@ -3,7 +3,7 @@
"""Database-related code specific for PostgreSQL."""
from sqlalchemy import create_engine
from sqlalchemy import BigInteger, JSONB
from sqlalchemy import BigInteger
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import scoped_session, sessionmaker
import transaction
@ -21,3 +21,12 @@ def getEngine(dbtype, dbname, user, pw, host='localhost', port=5432, **kw):
def commit(conn):
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

View file

@ -9,6 +9,7 @@ app = zope_app
# storage settings
# PostgreSQL
import scopes.storage.db.postgres
dbengine = 'postgresql+psycopg'
dbname = 'testdb'
dbuser = 'testuser'
@ -16,7 +17,7 @@ dbpassword = 'secret'
dbschema = 'testing'
# SQLite
dbengine = 'sqlite'
dbname = 'var/test.db'
dbschema = None
#dbengine = 'sqlite'
#dbname = 'var/test.db'
#dbschema = None

View file

@ -17,9 +17,7 @@ engine = getEngine(config.dbengine, config.dbname, config.dbuser, config.dbpassw
scopes.storage.common.engine = engine
scopes.storage.common.Session = sessionFactory(engine)
#storage = Storage(schema='testing')
#storage = Storage(schema=config.dbschema)
storage = Storage()
storage = Storage(schema=config.dbschema)
class Test(unittest.TestCase):
@ -86,8 +84,7 @@ class Test(unittest.TestCase):
self.assertEqual(ch1.parent, top.rid)
assert list(top.keys()) == ['child1']
#transaction.commit()
storage.session.commit()
commit(storage.session)
def suite():
return unittest.TestSuite((