Configuring database models

Our database models live in their usual folders: Sources/App/Models. Follow the steps given below:

  1. Open the Sources/App/Models/Database folder, either in Finder or Xcode, and add a new Order.swift file, and enter the following code for the file:
import Fluentimport Vaporfinal class Order: Model {    static let schema = "orders"        @ID(key: "id")    var id: Int?    @Field(key: "totalAmount")    var totalAmount: Int    @Field(key: "paidAmount")    var paidAmount: Int    @Field(key: "userId")    var userId: Int    @Field(key: "status")    var status: Int    @Timestamp(key: "createdAt", on: .create)    var createdAt: Date?        @Timestamp(key: "updatedAt", on: .update)    var updatedAt: Date?        @Timestamp(key: "deletedAt", on: .delete)    var deletedAt: Date?

Get Hands-On Swift 5 Microservices Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.