コード例 #1
0
 def get_courses_by_teacher_id(teacher_id):
     sql = "SELECT * FROM courses WHERE teacher_id=%s"
     cursor = connection.cursor()
     cursor.execute(sql, [teacher_id])
     records = cursor.fetchall()
     courses_list = []
     for record in records:
         course = Courses(record[0], record[1], record[2])
         courses_list.append(course.json())
     return courses_list
コード例 #2
0
 def all_courses(self):  # Retrieve all Course from courses and return
     sql = "SELECT * FROM courses"
     cursor = connection.cursor()
     cursor.execute(sql)
     records = cursor.fetchall()
     courses_list = []
     for record in records:
         course = Courses(record[0], record[1], record[2])
         courses_list.append(course.json())
     return courses_list
コード例 #3
0
    def get_courses(
        self, empid
    ):  # Retrieve a single Course for an employee by passing an  employee ID
        sql = "SELECT * FROM courses WHERE  empid=%s "
        cursor = connection.cursor()
        cursor.execute(sql, [empid])
        record = cursor.fetchall()

        courses_list = []
        for records in record:
            course = Courses(records[0], records[1], records[2])
            courses_list.append(course.json())
        return courses_list