From the course: Using Vapor with SQL and NoSQL Databases
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Overview of the Model protocol - Swift Tutorial
From the course: Using Vapor with SQL and NoSQL Databases
Overview of the Model protocol
- [Instructor] In Vapor a model is not only a representation of your data, it's also the base protocol for any of your application's models. Especially the ones that you want to persist to a database. A model is only available in Vapor. Its Fluent equivalent is called an entity. When working with a model, you must import Vapor and Fluent. Model objects must conform to the model protocol. When doing so, you'll be informed of some missing items that are required. First, every model must have a property called id. This is your identifier. It's of optional type node, and it's declared like this. Next, you have to provide a means to create a model from the persisted data. To do so, it should be what's called node initializable. To do this, you need to implement a particular init method, and that signature is init, node, in context and it throws. What this function tries to do is when pulling data from a database, it's going to try to create your model object, and in doing so will try to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Overview of the Model protocol2m 53s
-
Implementing your Model5m 22s
-
Controller implementation7m 3s
-
CRUD operations6m 54s
-
Database preparation and reverting4m 33s
-
Working with dynamic Leaf templates6m 50s
-
Working with multipart form data, part 16m 30s
-
Working with multipart form data, part 24m 38s
-
-
-
-