Once Postico is installed, you can connect to PostgreSQL on Docker just like you would if PostgreSQL was running on your local machine without Docker since you mapped your local port of 5432 to the container’s port of 5432. There is a paid version as well that gives you more advanced features, but you’ll only need the free features. Postico is a great free PostgresQL client for macOS that you can use for this tutorial. The Content protocol is added so that you can use this model in your router. There’s also PostgreSQLModel and PostgreSQLStringModel protocols for models with IDs of type Int or String. The Fluent packages provide Model convenience protocols for each database provider and tell Fluent which type the ID will be. Next, you’ll add two extensions to Room.swift that make the Room class conform to convenience protocols. The class is marked final to provide performance benefits by the compiler. All Fluent models must conform to Codable. Once the Room has been saved, it’s ID is set. The model class contains a single optional UUID property to hold a room’s unique identifier if it has been set. In Xcode, create a new file within the Sources/App/Models folder, and call the new file Room.swift:Ĭhange the contents of the new file to the following: You’ll start by creating a model class for the conference room data you want to migrate. The steps to connect to Postgres through your Vapor application are already implemented in the starter project in Sources/App/configure.swift. Maps the host port 5432, which is the default port for Postgres, to the container port 5432.Specifies the database name, username and password through environment variables.Pulls down the image if it currently does not exist on your machine.e POSTGRES_USER=vapor -e POSTGRES_PASSWORD=password \ Assuming you have Docker installed and running on macOS, in Terminal, enter the following command:ĭocker run -name postgres -e POSTGRES_DB=vapor \ This tutorial requires you to run PostgreSQL on Docker. The second command opens the project in Xcode, using Xcode 11’s new SwiftPM integrations. The first command takes you into the directory of the starter project for the RoomFinder app. Unzip the downloaded file and then from a Terminal, cd into the folder that was unzipped and enter the following commands: RoomFinder is a Vapor application to model conference rooms for your new startup. If you need a refresher on Docker, see Docker on macOS: Getting Started.ĭownload the starter project at the top or bottom of this page by clicking on the Download Materials button. See Getting Started with Server-side Swift with Vapor if you’re new to Vapor and Using Fluent and Persisting Models in Vapor if you’re new to Fluent. Note: This tutorial assumes you have some experience with using Vapor to build web apps, as well as have a basic understanding of Fluent.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |