Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vapor - How to access the FluentValue type?

Tags:

vapor

This is a Swift, Vapor related question.

How do I access the FluentValue type when trying to create a ResponseRepresentable Class?

The Vapor Model Protocol demands an ID; I want to assign my ID variable as a FluentValue optional. However, I can't find it (even after Import Vapor & Import Fluent).

import Vapor
import VaporMySQL

let drop = Droplet()

drop.post(String.self, "boughtcoffee")     { request, buyerName in

   let coffeeledger = CoffeeLedger(name: buyerName, time: 0)

   guard let atLeastOneDrinker = request.data["drinker"].string else { 
       throw Abort.custom(status: .badRequest, message: "Please enter some drinkers")
}
     return coffeeledger
}

import Vapor import Fluent

final class CoffeeLedger: Model {
    var id: FluentValue?
    var name: String
    var time: Int

    init (name: String, time: Int){
        self.name = name
        self.time = time
    }
}

I am following the Vapor video on setting up a Model that is Response Representable. https://www.youtube.com/watch?v=E1ir7_s_VTw

like image 978
rustyMagnet Avatar asked Dec 06 '25 06:12

rustyMagnet


1 Answers

FluentValue became Node in Vapor 0.15. (Current version of Vapor at this time is 0.16).

Additionally, the init and serialize methods became init(node: ...) and makeNode().

The code on the model page (https://vapor.github.io/documentation/fluent/model.html) should be up to date and working with Vapor 0.15 and later.

If there is a specific error you are getting, create another question here with that error message and I can try to help!

like image 197
tanner0101 Avatar answered Dec 08 '25 20:12

tanner0101



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!