diff --git a/sqli/dao/student.py b/sqli/dao/student.py index d41ef885..a770ea2f 100644 --- a/sqli/dao/student.py +++ b/sqli/dao/student.py @@ -25,13 +25,13 @@ async def get(conn: Connection, id_: int): async def get_many(conn: Connection, limit: Optional[int] = None, offset: Optional[int] = None): q = 'SELECT id, name FROM students' - params = {} + params = [] if limit is not None: - q += ' LIMIT + %(limit)s ' - params['limit'] = limit + q += ' LIMIT %s' + params.append(limit) if offset is not None: - q += ' OFFSET + %(offset)s ' - params['offset'] = offset + q += ' OFFSET %s' + params.append(offset) async with conn.cursor() as cur: await cur.execute(q, params) results = await cur.fetchall() @@ -39,9 +39,8 @@ async def get_many(conn: Connection, limit: Optional[int] = None, @staticmethod 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) - - + await cur.execute( + "INSERT INTO students (name) VALUES (%s)", + (name,) + )