databases
databases copied to clipboard
The documentation does not describe the return values for the database.execute (LAST_INSERT_ID)
async with database.transaction() as transaction:
query = insert(Session).values({"foo": "bar"})
last_insert_id = await database.execute(query)
(uid, ) = await database.fetch_one("SELECT LAST_INSERT_ID() as id")
assert uid == last_inserted_id # True
It is possible to extract last_insert_id from the database.execute call, but this is not mentioned in the documentation.
It is also not clear from the documentation what is the difference between database.fetch_one and database.execute. Why is it that calling database.execute("SELECT LAST_INSERT_ID() as id") won't produce the same result?