mirror of
https://github.com/ada-dmitry/lab6.git
synced 2026-09-24 09:20:15 +00:00
rebase 0.4 and create 0.5
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# Таблица Телефоны и особые действия с ней.
|
||||
|
||||
from dbtable import *
|
||||
|
||||
class PhonesTable(DbTable):
|
||||
def table_name(self):
|
||||
return self.dbconn.prefix + "phones"
|
||||
|
||||
def columns(self):
|
||||
return {"person_id": ["integer", "REFERENCES people(id)"],
|
||||
"phone": ["varchar(12)", "NOT NULL"]}
|
||||
|
||||
def primary_key(self):
|
||||
return ['person_id', 'phone']
|
||||
|
||||
def table_constraints(self):
|
||||
return ["PRIMARY KEY(person_id, phone)"]
|
||||
|
||||
def all_by_person_id(self, pid):
|
||||
sql = "SELECT * FROM " + self.table_name()
|
||||
sql += " WHERE person_id = %s"
|
||||
sql += " ORDER BY "
|
||||
sql += ", ".join(self.primary_key())
|
||||
cur = self.dbconn.conn.cursor()
|
||||
cur.execute(sql, str(pid))
|
||||
return cur.fetchall()
|
||||
|
||||
Reference in New Issue
Block a user