Ejemplo n.º 1
0
 async def create(conn: Connection,
                  title: str,
                  description: Optional[str] = None):
     q = ('INSERT INTO courses (title, description) '
          'VALUES (%(title)s, %(description)s)')
     async with conn.cursor() as cur:
         await cur.execute(q, {'title': title, 'description': description})
Ejemplo n.º 2
0
 async def create(conn: Connection, name: str):
     q = ("INSERT INTO students (name) "
          "VALUES ('%(name)s')" % {
              'name': name
          })
     async with conn.cursor() as cur:
         await cur.execute(q)
Ejemplo n.º 3
0
 async def get(conn: Connection, id_: int):
     async with conn.cursor() as cur:
         await cur.execute(
             'SELECT id, title, description '
             'FROM courses WHERE id = %s',
             (id_, ),
         )
         return Course.from_raw(await cur.fetchone())
Ejemplo n.º 4
0
 async def get(conn: Connection, id_: int):
     async with conn.cursor() as cur:
         await cur.execute(
             'SELECT id, name FROM students WHERE id = %s',
             (id_, ),
         )
         r = await cur.fetchone()
         return Student.from_raw(r)
Ejemplo n.º 5
0
 async def get_for_course(conn: Connection, course_id: int):
     q = ('SELECT id, date, course_id, review_text '
          'FROM course_reviews WHERE course_id = %s '
          'ORDER BY date')
     params = (course_id, )
     async with conn.cursor() as cur:
         await cur.execute(q, params)
         result = await cur.fetchall()
         return [Review.from_raw(r) for r in result]
Ejemplo n.º 6
0
 async def get_for_student(conn: Connection, student_id: int):
     q = ('SELECT id, date, student_id, course_id, points '
          'FROM marks WHERE student_id = %s '
          'ORDER BY course_id, date')
     params = (student_id, )
     async with conn.cursor() as cur:
         await cur.execute(q, params)
         result = await cur.fetchall()
         return [Mark.from_raw(r) for r in result]
Ejemplo n.º 7
0
 async def create(conn: Connection, student_id: int, course_id: int,
                  points: int):
     q = ('INSERT INTO marks (student_id, course_id, points) '
          'VALUES (%(student_id)s, %(course_id)s, %(points)s)')
     params = {
         'student_id': student_id,
         'course_id': course_id,
         'points': points
     }
     async with conn.cursor() as cur:
         await cur.execute(q, params)
Ejemplo n.º 8
0
 async def get_many(conn: Connection,
                    limit: Optional[int] = None,
                    offset: Optional[int] = None):
     q = 'SELECT id, title, description FROM courses'
     params = {}
     if limit is not None:
         q += ' LIMIT + %(limit)s '
         params['limit'] = limit
     if offset is not None:
         q += ' OFFSET + %(offset)s '
         params['offset'] = offset
     async with conn.cursor() as cur:
         await cur.execute(q, **params)
         result = await cur.fetchall()
         return [Course.from_raw(r) for r in result]
Ejemplo n.º 9
0
 async def get_many(conn: Connection,
                    limit: Optional[int] = None,
                    offset: Optional[int] = None):
     q = 'SELECT id, name FROM students'
     params = {}
     if limit is not None:
         q += ' LIMIT + %(limit)s '
         params['limit'] = limit
     if offset is not None:
         q += ' OFFSET + %(offset)s '
         params['offset'] = offset
     async with conn.cursor() as cur:
         await cur.execute(q, params)
         results = await cur.fetchall()
         return [Student.from_raw(r) for r in results]
Ejemplo n.º 10
0
 async def create(conn: Connection, course_id: int, review_text: str):
     q = ('INSERT INTO course_reviews (course_id, review_text) '
          'VALUES (%(course_id)s, %(review_text)s)')
     params = {'course_id': course_id, 'review_text': review_text}
     async with conn.cursor() as cur:
         await cur.execute(q, params)