Merge branch 'master' into master

This commit is contained in:
Tanner 2017-06-02 16:43:55 +01:00 committed by GitHub
commit c8a856f0e8
7 changed files with 32 additions and 15 deletions

View File

@ -58,10 +58,10 @@ The above prepare statement results in SQL similar to the following:
CREATE TABLE `users` (`id` INTEGER PRIMARY KEY NOT NULL, `name` TEXT NOT NULL, `age` INTEGER NOT NULL)
```
Once you have created you preparation, add it to the Droplet's prepratations array.
Once you have created you preparation, add it to the Config's prepratations array.
```swift
drop.preparations.append(User.self)
config.preparations.append(User.self)
```
### Create

View File

@ -18,13 +18,23 @@ final class Pet: Model {
var name: String
var age: Int
let storage = Storage()
init(row: Row) throws {
name = try row.get("name")
age = try row.get("age")
}
init(name: String, age: Int) {
self.name = name
self.age = age
}
...
func makeRow() throws -> Row {
var row = Row()
try row.set("name", name)
try row.set("age", age)
return row
}
}
```
@ -82,7 +92,7 @@ You can do this by conforming your model to `Preparation`.
extension Pet: Preparation {
static func prepare(_ database: Database) throws {
try database.create(self) { pets in
pets.id(for: self)
pets.id()
pets.string("name")
pets.int("age")
}
@ -102,15 +112,15 @@ Here we are creating a simple table that will look like this:
### Add to Droplet
Now you can add your model to the Droplet's prearations so the database is prepared when your application boots.
Now you can add your model to the config's prearations so the database is prepared when your application boots.
```swift
import Vapor
import FluentProvider
let drop = try Droplet()
drop.preparations.append(Pet.self)
let config = try Config()
config.preparations.append(Pet.self)
let drop = try Droplet(config)
...
```

View File

@ -164,5 +164,5 @@ Some debug messages will be silenced while in the production environment, so mak
!!! warning
If you compiled your application with `--release`, make sure to add that flag to the `vapor run` command as well. e.g., `vapor run serve --env=production --release`.
For more information on deploying your code, check out the [deploy section](https://docs.vapor.codes/2.0/deploy/nginx/).
For more information on deploying your code, check out the [deploy section](../deploy/nginx.md).

View File

@ -8,6 +8,12 @@ You can build, run, and stop your server from within Xcode, as well as use break
To use Xcode, you will first need to generate a `*.xcodeproj` file.
### Select 'Run'
Make sure after generating your Xcode project that you properly select the executable if you're trying to run your application.
<img src="https://cloud.githubusercontent.com/assets/6710841/26517851/72841fd6-426f-11e7-9e6c-945d22933094.png" alt="select 'run' from dropdown" width="300">
## Generate Project
### Vapor Toolbox

View File

@ -48,7 +48,7 @@ req.formURLEncoded = Node(node: [
"email": "mymail@vapor.codes"
])
try drop.client.response(to: req)
try drop.client.respond(to: req)
```
## Re-usable Connection

View File

@ -43,9 +43,8 @@ You can also set the `drop.view` property manually if you want to hardcode your
import Vapor
import LeafProvider
let drop = try Droplet()
drop.view = LeafRenderer(viewsDir: drop.viewsDir)
let view = LeafRenderer(viewsDir: drop.viewsDir)
let drop = try Droplet(view: view)
```
## Done

View File

@ -73,7 +73,9 @@ pages:
- 'Package': 'leaf/package.md'
- 'Provider': 'leaf/provider.md'
- 'Overview': 'leaf/leaf.md'
- Validation: 'validation/overview.md'
- Validation:
- 'Package': 'validation/package.md'
- 'Overview': 'validation/overview.md'
- Node:
- 'Package': 'node/package.md'
- 'Getting Started': 'node/getting-started.md'