# Server Side Swift with Vapor - Part 15: Persisting | Ray Wenderlich

**URL:** <https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904>\
**Category:** 🎓 Courses & Articles\
**Created:** [March 1, 2018, 6:14pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904 "2018-03-01T18:14:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 1, 2018, 6:14pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/1 "2018-03-01T18:14:57Z")

</div>

Learn how to set up your Vapor application to use MySQL as a database, using Docker, so your data is persisted.

* * *
 This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/4493-server-side-swift-with-vapor/lessons/15](https://www.raywenderlich.com/4493-server-side-swift-with-vapor/lessons/15)

---

<div class="post-metadata">

**Author:** ![fahim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fahim/32/110943_2.png) [@fahim](https://forums.kodeco.com/u/fahim)\
**Post date:** [March 7, 2018, 4:12am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/2 "2018-03-07T04:12:09Z")

</div>

This might be an obvious point, but just mentioning it for the sake of those who might not have thought of this 🙂

For those who already have MySQL running on their machine either via something like MAMP or XAMPP or some other means, you don’t really have to install Docker - unless you really want to, of course 🙂 You can simply use your existing MySQL server to work with Vapor. While I do have Docker set up already, I also have an existing MySQL installation via MAMP and I simply used that for the tutorial.

I do realize why Docker was used for the tutorial since that is easier than running the viewer/student through a full MySQL installation, but just mentioning this in case this does prove to be useful to someone out there …

---

<div class="post-metadata">

**Author:** ![amyerson](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@amyerson](https://forums.kodeco.com/u/amyerson)\
**Post date:** [March 24, 2018, 11:45am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/3 "2018-03-24T11:45:49Z")

</div>

I’m getting 2 MySQL Compiling errors (for the build end of the video):  
type ‘SHA1’ has no member ‘digest’  
value of type ‘Data’ has no member ‘hexEncodedString’

[https://drive.google.com/open?id=1kYcLmKI7TbYUyuvFSF1kn54tdYo4SEU9](https://drive.google.com/open?id=1kYcLmKI7TbYUyuvFSF1kn54tdYo4SEU9)  
[https://drive.google.com/open?id=1e03yQyqnn3xELxEBw-lRUfEfpJ-WF8mR](https://drive.google.com/open?id=1e03yQyqnn3xELxEBw-lRUfEfpJ-WF8mR)  
[https://drive.google.com/open?id=1SEvio4I-aNdhy\_tMDGVcjm4G1NIkUQox](https://drive.google.com/open?id=1SEvio4I-aNdhy_tMDGVcjm4G1NIkUQox)  
[https://drive.google.com/open?id=1BsbidHQtsjYRldiAR9Vw4tMNzjsjKssR](https://drive.google.com/open?id=1BsbidHQtsjYRldiAR9Vw4tMNzjsjKssR)

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 24, 2018, 12:28pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/4 "2018-03-24T12:28:15Z")

</div>

@amyerson I’m not seeing those errors, can you make sure your Package.swift looks like:

```swift
// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "TILApp",
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent-mysql.git", from: "3.0.0-rc"),
    ],
    targets: [
        .target(name: "App", dependencies: ["FluentMySQL", "Vapor"]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App"]),
    ]
)

```

And run `vapor update` in Terminal to make sure you have the latest RC

---

<div class="post-metadata">

**Author:** ![andrekilik](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/andrekilik/32/81494_2.png) [@andrekilik](https://forums.kodeco.com/u/andrekilik)\
**Post date:** [March 25, 2018, 7:52pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/5 "2018-03-25T19:52:33Z")

</div>

I’m getting an error, after I changed my pivot to a MySQLUUIDPivot, the searchHandler method broke.

```
return try Acronym.query(on: req).group(or) { or in
        or.filter(\.short == searchTerm).all()
        or.filter(\.long == searchTerm).all()
    }.all()

```

I get the “Use of unresolved identifier or” message. The “OR” giving the error is the one inside the .group(or). I’ve been messing around with it, but couldn’t find a way to fix.

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 25, 2018, 8:06pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/6 "2018-03-25T20:06:28Z")

</div>

@andrekilik 🤔 change the Pivot shouldn’t affect that file! Are you on RC2?

---

<div class="post-metadata">

**Author:** ![fahim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fahim/32/110943_2.png) [@fahim](https://forums.kodeco.com/u/fahim)\
**Post date:** [March 26, 2018, 12:16am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/7 "2018-03-26T00:16:00Z")

</div>

On RC2, I had to re-write the search handler as follows in order to get it to compile:

```
return try Acronym.query(on: req).group(.or, closure: {(or) in
	try or.filter(\.short == term)
	try or.filter(\.long == term)
}).all()

```

Note the two `try` statements within the closure 🙂

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 26, 2018, 9:12am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/8 "2018-03-26T09:12:42Z")

</div>

@fahim in case you haven’t seen it, all the changes required for RC2 are here [Changes for the Ray Wenderlich Vapor Videos for Vapor 3 RC 2 · GitHub](https://gist.github.com/0xTim/b372f91c8bd71ea757d1da526058f2d9)

---

<div class="post-metadata">

**Author:** ![fahim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fahim/32/110943_2.png) [@fahim](https://forums.kodeco.com/u/fahim)\
**Post date:** [March 26, 2018, 9:26am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/9 "2018-03-26T09:26:12Z")

</div>

> [@0xtim](#):
>
> @fahim in case you haven’t seen it, all the changes required for RC2 are here [Changes for the Ray Wenderlich Vapor Videos for Vapor 3 RC 2 · GitHub](https://gist.github.com/0xTim/b372f91c8bd71ea757d1da526058f2d9)

Thanks, Tim 🙂 I did see that and have it bookmarked. I was just responding to @andrekilik since I believe the error he was talking about was the one I mentioned.

---

<div class="post-metadata">

**Author:** ![fjrivash](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fjrivash/32/78601_2.png) [@fjrivash](https://forums.kodeco.com/u/fjrivash)\
**Post date:** [March 27, 2018, 10:24am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/10 "2018-03-27T10:24:46Z")

</div>

Hello,

This is my Package.swift

$ cat Package.swift  
// swift-tools-version:4.0  
import PackageDescription

let package = Package(  
name: “TILApp”,  
dependencies: [  
// 💧 A server-side Swift web framework.  
.package(url: “[GitHub - vapor/vapor: 💧 A server-side Swift HTTP web framework.](https://github.com/vapor/vapor.git)”, from: “3.0.0-rc.2”),  
.package(url: “[GitHub - vapor/fluent-mysql-driver: 🖋🐬 Swift ORM (queries, models, relations, etc) built on MySQL.](https://github.com/vapor/fluent-mysql.git)”, from: “3.0.0-rc.2”)  
],  
targets: [  
.target(name: “App”, dependencies: [“FluentMySQL”, “Vapor”]),  
.target(name: “Run”, dependencies: [“App”]),  
.testTarget(name: “AppTests”, dependencies: [“App”])  
]  
)

I was also getting the same error as @amyerson regarding the “digest” and “encoding”

Then after doing “vapor update” seems everything is updated and no longer have those errors.

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 27, 2018, 12:01pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/11 "2018-03-27T12:01:02Z")

</div>

Is it all working again then?

---

<div class="post-metadata">

**Author:** ![fjrivash](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fjrivash/32/78601_2.png) [@fjrivash](https://forums.kodeco.com/u/fjrivash)\
**Post date:** [March 27, 2018, 4:31pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/12 "2018-03-27T16:31:43Z")

</div>

Thank you very much Tim. It is working again, yes. I do not have those 2 MySQL compiling errors anymore.

---

<div class="post-metadata">

**Author:** ![andy4202](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/andy4202/32/81494_2.png) [@andy4202](https://forums.kodeco.com/u/andy4202)\
**Post date:** [March 31, 2018, 6:10pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/13 "2018-03-31T18:10:49Z")

</div>

I keep getting the compile error 'Missing required module ‘CSQLite’.

This is Package.swift

// swift-tools-version:4.0  
import PackageDescription

let package = Package(  
name: “TILApp”,  
dependencies: [  
// 💧 A server-side Swift web framework.  
.package(url: “[GitHub - vapor/vapor: 💧 A server-side Swift HTTP web framework.](https://github.com/vapor/vapor.git)”, from: “3.0.0-rc”),

```
    // 🔵 Swift ORM (queries, models, relations, etc) built on SQLite 3.
    .package(url: "https://github.com/vapor/fluent-mysql.git", from: "3.0.0-rc")
],
targets: [
    .target(name: "App", dependencies: ["FluentMySQL", "Vapor"]),
    .target(name: "Run", dependencies: ["App"]),
    .testTarget(name: "AppTests", dependencies: ["App"])
]

```

)

Does anyone know a way to get this to compile?

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 31, 2018, 11:00pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/14 "2018-03-31T23:00:36Z")

</div>

@andy4202 that usually means you have leftover references to SQLite somewhere in your code, something like an `import FluentSQLite` or `SQLiteModel` lying around somewhere. If you do `rm -rf .build` to remove any old build artefacts and regenerate the project it should point of the actual error if you can’t find it

---

<div class="post-metadata">

**Author:** ![gargoyle](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gargoyle/32/107285_2.png) [@gargoyle](https://forums.kodeco.com/u/gargoyle)\
**Post date:** [April 8, 2018, 5:31pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/15 "2018-04-08T17:31:39Z")

</div>

It seems like PostgreSQL setup is quite different than what you’ve shown. Any chance you’ll be doing a video on using that database? For example, I don’t see anything like the automated model setup interfaces that you used with MySQL

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [April 8, 2018, 9:09pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/16 "2018-04-08T21:09:05Z")

</div>

@gargoyle they should be almost identical. See this project which is similar but uses Postgres instead of MySQL

---

<div class="post-metadata">

**Author:** ![gargoyle](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gargoyle/32/107285_2.png) [@gargoyle](https://forums.kodeco.com/u/gargoyle)\
**Post date:** [April 8, 2018, 11:36pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/17 "2018-04-08T23:36:31Z")

</div>

@0xtim Please include the link 🙂

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [April 9, 2018, 6:56am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/18 "2018-04-09T06:56:00Z")

</div>

🤦‍♂️

Here you go! [GitHub - raywenderlich/vapor-til: The TIL Application for the Vapor book](https://github.com/raywenderlich/vapor-til)

---

<div class="post-metadata">

**Author:** ![a\_stefka](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/a_stefka/32/81494_2.png) [@a\_stefka](https://forums.kodeco.com/u/a_stefka)\
**Post date:** [May 11, 2018, 9:16pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/19 "2018-05-11T21:16:28Z")

</div>

Hi Tim,

cool tutorial - very good - up to now I was successful in building it as described and shown in the video clips.

I hope this is the right place to post my question, when running the project from Xcode (already changed to FluentMySQL DB connection) I get the following error message

Thread 1: Fatal error: Error raised at top level: ⚠ MySQL Error: Unsupported auth plugin: caching\_sha2\_password

- id: MySQLError.authPlugin

File: /App-Programmierung/DB\_Access/VAPOR/TILAPP/.build/checkouts/mysql.git-1890032512239690518/Sources/MySQL/Connection/MySQLConnection+Authenticate.swift

- func: authenticate(username:database:password:)
- line: 46
- column: 143

Username/Password/Database is set correct as stated within docker MySQL command, and MySQL within docker is running.

Package.swift is correct as stated in your post.

It would be fine if you can give me a hint what I have done wrong.

Many thanks!!

Alex

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [May 11, 2018, 9:21pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904/20 "2018-05-11T21:21:26Z")

</div>

@a_stefka you haven’t done anything wrong! Unfortunately MySQL 10.0.2(?) introduced a new default authentication module that Vapor doesn’t support yet. There’s an issue open but for now you can do:

```bash
docker run --name mysql -e MYSQL_USER=vapor \
  -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=vapor \
  -p 3306:3306 -d mysql/mysql-server:5.7

```

This specifies the 5.7 MySQL Server which still works

[Next page](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-15-persisting-ray-wenderlich/39904.md?page=2)
