-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2112 from stevepiercy/feature/alchemy-scaffold-up…
…date Finish work on basiclayout.rst and its src at wiki2/src/basiclayout/
- Loading branch information
Showing
13 changed files
with
243 additions
and
147 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
docs/tutorials/wiki2/src/basiclayout/tutorial/models/__init__.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from sqlalchemy.orm import configure_mappers | ||
# import all models classes here for sqlalchemy mappers | ||
# to pick up | ||
from .mymodel import MyModel # flake8: noqa | ||
|
||
# run configure mappers to ensure we avoid any race conditions | ||
configure_mappers() |
46 changes: 46 additions & 0 deletions
46
docs/tutorials/wiki2/src/basiclayout/tutorial/models/meta.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from sqlalchemy import engine_from_config | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
from sqlalchemy.schema import MetaData | ||
import zope.sqlalchemy | ||
|
||
NAMING_CONVENTION = { | ||
"ix": 'ix_%(column_0_label)s', | ||
"uq": "uq_%(table_name)s_%(column_0_name)s", | ||
"ck": "ck_%(table_name)s_%(constraint_name)s", | ||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | ||
"pk": "pk_%(table_name)s" | ||
} | ||
|
||
metadata = MetaData(naming_convention=NAMING_CONVENTION) | ||
Base = declarative_base(metadata=metadata) | ||
|
||
|
||
def includeme(config): | ||
settings = config.get_settings() | ||
dbmaker = get_dbmaker(get_engine(settings)) | ||
|
||
config.add_request_method( | ||
lambda r: get_session(r.tm, dbmaker), | ||
'dbsession', | ||
reify=True | ||
) | ||
|
||
config.include('pyramid_tm') | ||
|
||
|
||
def get_session(transaction_manager, dbmaker): | ||
dbsession = dbmaker() | ||
zope.sqlalchemy.register(dbsession, | ||
transaction_manager=transaction_manager) | ||
return dbsession | ||
|
||
|
||
def get_engine(settings, prefix='sqlalchemy.'): | ||
return engine_from_config(settings, prefix) | ||
|
||
|
||
def get_dbmaker(engine): | ||
dbmaker = sessionmaker() | ||
dbmaker.configure(bind=engine) | ||
return dbmaker |
17 changes: 17 additions & 0 deletions
17
docs/tutorials/wiki2/src/basiclayout/tutorial/models/mymodel.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from .meta import Base | ||
from sqlalchemy import ( | ||
Column, | ||
Index, | ||
Integer, | ||
Text, | ||
) | ||
|
||
|
||
class MyModel(Base): | ||
__tablename__ = 'models' | ||
id = Column(Integer, primary_key=True) | ||
name = Column(Text) | ||
value = Column(Integer) | ||
|
||
|
||
Index('my_index', MyModel.name, unique=True, mysql_length=255) |
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
2 changes: 1 addition & 1 deletion
2
docs/tutorials/wiki2/src/basiclayout/tutorial/static/theme.min.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.