sqlitesqldelight

Get row id for inserted row in sqldelight


I'm trying to use sqldelight to insert an item, but to also return the id of the item after it's inserted. There doesn't seem to be a way to do this in sqldelight.

I can call something like SELECT last_insert_rowid(); after I do the insert, but is this the best way to move forward?


Solution

  • You can add this command to your .sq file:

    lastInsertRowId:
    SELECT last_insert_rowid()
    ;
    

    And it will return you an id of last inserted row.

    Please refer to this issue on Github for more info.