Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
orm_in_class
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Brady James Garvin
orm_in_class
Commits
fbaa9153
Commit
fbaa9153
authored
6 years ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Updated code for Python 3.
parent
90b6329a
Branches
master
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
diner.py
+3
-4
3 additions, 4 deletions
diner.py
diner_installer.py
+1
-3
1 addition, 3 deletions
diner_installer.py
with
4 additions
and
7 deletions
diner.py
+
3
−
4
View file @
fbaa9153
...
...
@@ -8,7 +8,7 @@ from sqlalchemy.orm import sessionmaker, relationship
# class that we can use for objects that we want SQLAlchemy to persist in a
# database. We then store that class in variable named Persisted; effectively,
# we make a new class called Persisted.
Persisted
=
declarative_base
()
Persisted
=
declarative_base
()
# pylint: disable=invalid-name
class
Menu
(
Persisted
):
...
...
@@ -42,8 +42,7 @@ class OrderItem(Persisted):
class
DinerDatabase
(
object
):
@staticmethod
def
construct_mysql_url
(
authority
,
port
,
database
,
username
,
password
):
return
'
mysql+mysqlconnector://{username}:{password}@{authority}:{port}/{database}
'
\
.
format
(
authority
=
authority
,
port
=
port
,
database
=
database
,
username
=
username
,
password
=
password
)
return
f
'
mysql+mysqlconnector://
{
username
}
:
{
password
}
@
{
authority
}
:
{
port
}
/
{
database
}
'
@staticmethod
def
construct_in_memory_url
():
...
...
@@ -51,7 +50,7 @@ class DinerDatabase(object):
def
__init__
(
self
,
url
):
self
.
engine
=
create_engine
(
url
)
# an engine is like an endpoint, something to connect to
self
.
Session
=
sessionmaker
()
# create a class for connections to that endpoint
self
.
Session
=
sessionmaker
()
# create a class for connections to that endpoint
/ pylint: disable=invalid-name
self
.
Session
.
configure
(
bind
=
self
.
engine
)
# associate the class with the endpoint
def
ensure_tables_exist
(
self
):
...
...
This diff is collapsed.
Click to expand it.
diner_installer.py
+
1
−
3
View file @
fbaa9153
# -*- coding: utf-8; -*-
from
sys
import
stderr
from
sqlalchemy.exc
import
SQLAlchemyError
...
...
@@ -34,7 +32,7 @@ def main():
print
(
'
Records created.
'
)
except
SQLAlchemyError
as
exception
:
print
(
'
Database setup failed!
'
,
file
=
stderr
)
print
(
'
Cause: {exception}
'
.
format
(
exception
=
exception
)
,
file
=
stderr
)
print
(
f
'
Cause:
{
exception
}
'
,
file
=
stderr
)
exit
(
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment