-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
28 lines (23 loc) · 1.08 KB
/
backend.py
File metadata and controls
28 lines (23 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sqlalchemy
from sqlalchemy import Column, Table, ForeignKey, Date
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
Base = automap_base()
# set the sqlalchemy engine to mysql server and connect
engine = sqlalchemy.create_engine(
"mysql://vedant:vedant@localhost/library_management")
# Reflect tables
Base.prepare(engine, reflect=True)
Book = Base.classes.books
Students = Base.classes.students
t_issues = Table(
'issues', Base.metadata,
Column('book_no', ForeignKey('books.Acc_no', ondelete='CASCADE', onupdate='CASCADE'), index=True, comment='The Accession number of the book issued'),
Column('student_id', ForeignKey('students.Admno', ondelete='CASCADE', onupdate='CASCADE'), index=True, comment='The Admission Number of the student who is issuing the book'),
Column('issue_date', Date, comment='The date of issuing the book'),
Column('return_date', Date, comment='The date of returning the book'),
comment='A table for storing info of issued books',
extend_existing = True
)
# Create a session
session = Session(engine)