简体   繁体   中英

Swift Vapor Fluent updating an existing row

I know you can do Model.delete() and Model.save()

Is there a way to update an existing row?

In Fluent 2.0 there is a property added to every Entity/Model:

let storage = Storage()

This object is holding additional information for each entity, if storage.exists is true it will update data when you call save() instead of trying to insert new item to database.

Reading Fluent's code, I believe it saves the fields that are "dirty". So, you would have to do something like this:

let user = try User.find(42)
user.name = "Other Name"
try user.save()

I didn't try this, but I'll do it soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM