import sqlalchemy engine create_engine sqlite dbvivaio echo True Base

  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
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import sqlalchemy
engine = create_engine('sqlite://dbvivaio', echo=True)
Base = declarative_base()
Class Clients(Base):
__tablename__= 'clients'
id = Column(Integer, primary_key=True)
name = Column(String),
surname = Column(String),
cell = Column(String),
address = Column(String)
def __init__(self, id, name, surname, cell, address):
self.id = id
self.name = name
self.surname = surname
self.cell = cell
self.address = address
def __repr__(self):
return "<Client(%s, %s, %s, %s, %s)>" % (self.id, self.name, self.surname, self.cell, self.address)
client_table = Clients.__table__
Class Job(Base):
__tablename__ = 'jobs'
id = Column(Integer, primary_key=True),
title = Column(String),
cph = Column(Float)
def __init__(self, id, title, cph):
self.id = id
self.title = title
self.cph = cph
def __repr__(self):
return "<Job(%s, %s, %s)>" % (self.id, self.title, self.cph)
jobs_table = Job.__table__
Class Worker(Base):
__tablename__ = 'workers'
id = Column(Integer, primary_key=True),
name = Column(String),
surname = Column(String),
address = Column(String),
hire_date = Column(Date),
agronomist = Column(Bool),
qualification_id = Column(Integer, ForeignKey('qualification.id')
qualification = relation(Qualification, backref=backref('qualification', order_by=id))
def __init__(self, id, name, surname, address, hire_date, agronomist, qualification):
self.id = id
self.name = name
self.surname = surname
self.address = address
self.hire_date = hire_date
self.agronomist = agronomist
self.qualification = qualification
def __repr__(self):
return "<Worker(%s, %s, %s, %s, %s, %s, %s)>" % (self.id, self.name, self.surname, self.address, self.hire_date, self.agronomist, self.qualification)
workers_table = Worker.__table__
Class Qualification(Base):
__tablename__ = 'qualification'
id = Column(Integer, primary_key=True),
descr = Column(String)
def __init__(self, id, descr):
self.id = id
self.descr = descr
def __repr__(self):
return "<Qualification(%s, %s)>" % (self.id, self.descr)
qualifications_table = Qualification.__table__
Class Worker_job(Base):
__tablename__ = 'workerjobs'
id = Column(Integer, primary_key=True),
worker_id = Column(Integer, ForeignKey('workers.id')),
worker = relation(Worker, backref=backref('workers', order_by=id)),
jobid = Column(Integer, ForeignKey('jobs.id'))
job = relation(Job, backref=backref('jobs', order_by=id))
workers_jobs_table = Worker_job.__table__
Class Job_request(Base):
__tablename__ = 'jobs_requests'
id = Column(Integer, primary_key=True),
request_date = Column(Date),
execution_date = Column(Date),
client_id = Column(Integer, ForeignKey('clients.id')),
client = relation(Client, backref=backref('clients', order_by=id)),
jobid = Column(Integer, ForeignKey('jobs.id')),
job = relation(Job, backref=backref('jobs', order_by=id)),
worker_id = Column(Integer, ForeignKey('workers.id')),
worker = relation(Worker, backref=backref('workers', order_by=id))
def __init__(self, id, request_date, execution_date, client_id, jobid, worker_id):
self.id = id
self.request_date = request_date
self.execution_date = execution_date
self.client_id = client_id
self.jobid = jobid
self.worker_id = worker_id
def __repr__(self):
return "<Job_request(%s, %s, %s, %s, %s)>" % (self.id, self.request_date, self.execution_date, self.client_id, self.jobid, self.worker_id)
jobs_requests_table = Job_request.__table__
Class Species(Base):
__tablename__ = 'species'
id = Column(Integer, primary_key=True),
name = Column(String),
season = Column(String),
cultivation = Column(String),
indoor = Column(Bool),
present = Column(Bool),
agronomistid = Column(Integer, ForeignKey('workers.id'))
agronomist = relation(Worker, backref=backref('workers', order_by=id))
def __init__(self, id, name, season, cultivation, indoor, present, agronomistid):
self.id = id
self.name = name
self.season = season
self.cultivation = cultivation
self.indoor = indoor
self.present = present
self.agronomistid = agronomistid
def __repr__(self):
return "<Species(%s, %s, %s. %s, %s, %s)>" % (self.id, self.name, self.season, self.cultivation, self.indoor, self.present, self.agronomistid)
species_table = Species.__table__
Class Type(Base):
__tablename__ = 'species_types'
id = Column(Integer, primary_key=True),
descr = Column(String),
price = Column(Float),
amount = Column(Integer),
species_id = Column(Integer, ForeignKey('species.id'))
species = relation(Species, backref=backref('species', order_by=id))
def __init__(self, id, descr, price, amount, speciesid):
self.id = id
self.descr = descr
self.price = price
self.amount = amount
self.species_id = species_id
def __repr__(self):
return "<Type(%s, %s, %s, %s)>" % (self.id, self.descr, self.price, self.amount, self.species_id)
types_table = Type.__table__
metadata = Base.metadata
metadata.create_all(engine)