How to set up a Vapor 3 project
-
How to write Models using Fluent
Fluent is a Swift ORM framework (queries, models, and relations) for building SQL and NoSQL database integrations.
Source: Vapor University. Here you will find many tutorials regarding the basics of any Vapor project (important: check that the version of Vapor used in the tutorial is Vapor 3).
You can find them here.
Vapor uses Swift Package Manager, a tool that automates the process of downloading, compiling and linking dependencies.
Inside Package.swift you will find all the info related to dependencies. An example is shown below:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "swift-training-backend",
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
.package(url: "https://github.com/vapor/fluent-postgresql.git", from: "1.0.0"),
.package(url: "https://github.com/vapor-community/pagination.git", from: "1.0.0")
],
targets: [
.target(name: "App", dependencies: ["Vapor", "FluentPostgreSQL", "Pagination"]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"])
]
)