Vapor 4 setup
-
Official Postgres Website: https://www.postgresql.org/
-
Postgres.app: https://postgresapp.com/downloads.html
-
POSTMAN: https://www.postman.com/downloads/
-
Vapor 4 Installation https://docs.vapor.codes/4.0/install/macos/
Terminal and printing the Swift's version.
-
swift --version
-
brew install vapor
-
vapor --help
-
vapor new hello -n
The -n flag gives you a bare bones template by automatically answering no to all questions.
- cd hello
- open Package.swift or open . or xed .
- xCode -> Command B or Terminal -> swift build - to build
- Edit scheme (make sure it selected the main folder top)
- Run then Tab Option, select Working Directory (for your project folder)
- Play run the server - Server starting on http://127.0.0.1:8080
- Open web browser localhost:8080/hello
- https://www.postgresql.org
- https://postgresapp.com/downloads.html Postgres.app with PostgreSQL 12
- Upon running PostgresSQL app - double click your username and it will launch a terminal.
- Type -> CREATE DATABASE YuourDBName;
- On CREATE DATABASE YOURDBName;
- Select Y to yes to use Fluent
- Select 1 for Postgres database then Vapor Terminal will show
- Type -> cd to your folder directory
- Type -> Open . Or Open Package.swift
-
Xcode file - Package.swift content
import PackageDescription
let package = Package(
name: "hello-postgres-vapor",
platforms: [
.macOS(.v10_15)
],
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-beta"),
.package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0-beta")
],
targets: [
.target(
name: "App",
dependencies: [
.product(name: "Fluent", package: "fluent"),
.product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
.product(name: "Vapor", package: "vapor")
- Can also update packages from Xcode -> File menu, Swift Package, Update to Latest Package Versions - to look and update for new rc (release version)
- Postman.com
Section 7: Performing CRUD Operations (Create Read Update Delete) on PostgreSQL Database
Xcode -> at configure.swift file content
import Vapor
import Fluent
import FluentPostgresDriver
// configures your application
public func configure(_ app: Application) throws {
// uncomment to serve files from /Public folder
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.databases.use(.postgres(hostname: "localhost", username: "postgres", password: "", database: "moviesdb"), as: .psql)
app.migrations.add(CreateMovie())
// register routes
try routes(app)
}