vapor / fluent-mysql-driver

🖋🐬 Swift ORM (queries, models, relations, etc) built on MySQL.
MIT License
78 stars 52 forks source link

Mysql LAST_INSERT_ID #172

Closed wendyliga closed 4 years ago

wendyliga commented 4 years ago

is there any LAST_INSERT_ID equivalent on fluent mysql ?

tanner0101 commented 4 years ago

Fluent automatically fetches the last insert ID when you create a new model. If you're using the MySQL driver directly, there's an optional onMetadata closure you can pass to get access to this and other query metadata: https://github.com/vapor/mysql-nio/blob/master/Sources/MySQLNIO/MySQLQueryCommand.swift#L13

wendyliga commented 4 years ago

@tanner0101 there's case when you want to insert to new table use latest inserted on other tables. it will be amazing if we could fetch the last inserted (auto increment) id.