First commit.
This commit is contained in:
commit
a3e676a0b0
13 changed files with 346 additions and 0 deletions
19
example_app/seed.py
Normal file
19
example_app/seed.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from .app import SessionLocal, engine
|
||||
from .models import Base, Author, Book
|
||||
|
||||
def run():
|
||||
Base.metadata.create_all(engine)
|
||||
s = SessionLocal()
|
||||
a1 = Author(name="Ursula K. Le Guin")
|
||||
a2 = Author(name="Octavia E. Butler")
|
||||
s.add_all([
|
||||
a1, a2,
|
||||
Book(title="The Left Hand of Darkness", author=a1),
|
||||
Book(title="A Wizard of Earthsea", author=a1),
|
||||
Book(title="Parable of the Sower", author=a2),
|
||||
])
|
||||
s.commit()
|
||||
s.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
Loading…
Add table
Add a link
Reference in a new issue