Skip to content

Commit

Permalink
Patched /tmp/tmp3m3ecsfc/sqli/dao/student.py
Browse files Browse the repository at this point in the history
  • Loading branch information
patched.codes[bot] committed Nov 11, 2024
1 parent 7b71765 commit 9850ad4
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions sqli/dao/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from aiopg.connection import Connection


class Student(NamedTuple):
id: int
name: str
Expand All @@ -27,21 +26,18 @@ async def get_many(conn: Connection, limit: Optional[int] = None,
q = 'SELECT id, name FROM students'
params = {}
if limit is not None:
q += ' LIMIT + %(limit)s '
q += ' LIMIT %s'
params['limit'] = limit
if offset is not None:
q += ' OFFSET + %(offset)s '
q += ' OFFSET %s'
params['offset'] = offset
async with conn.cursor() as cur:
await cur.execute(q, params)
await cur.execute(q, (params.get('limit'), params.get('offset')))
results = await cur.fetchall()
return [Student.from_raw(r) for r in results]

@staticmethod
async def create(conn: Connection, name: str):
q = ("INSERT INTO students (name) "
"VALUES ('%(name)s')" % {'name': name})
q = "INSERT INTO students (name) VALUES (%s)"
async with conn.cursor() as cur:
await cur.execute(q)


await cur.execute(q, (name,))

0 comments on commit 9850ad4

Please sign in to comment.