Last active
July 13, 2021 10:18
-
-
Save davidjb/9107107 to your computer and use it in GitHub Desktop.
Example SQLAlchemy integration with Plone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[buildout] | |
... | |
[instance] | |
... | |
eggs= | |
... | |
z3c.saconfig | |
zcml-additional = | |
... | |
<configure xmlns="http://namespaces.zope.org/zope" | |
xmlns:db="http://namespaces.zope.org/db"> | |
<include package="z3c.saconfig" file="meta.zcml" /> | |
<db:engine name="my_engine_name" | |
url="mysql://david:password@localhost/my_db_name" | |
setup="my.example.prepare_model.prepare" | |
/> | |
<db:session name="session" engine="my_engine_name" /> | |
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prepare(engine): | |
# ``Base`` is a declarative_base object used for ORM classes. | |
from my.example import Base | |
# Need to import models so Base.metadata is aware of their existence | |
import my.example.models | |
# Binds the SQLAlchemy engine to the models' metadata so they can be accessed | |
Base.metadata.create_all(engine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment