Server Side Swift with Vapor: Configuring a Database | Ray Wenderlich

@alexhedley Awesome, I’m glad you got it working! :thumbsup:

1 Like

What did you reinstall, exactly? I have the same issues that you had, and reinstalling postgres didn’t fix it.

I ran

brew uninstall <same package name>

finally have a chance to sit down and go through all the screencasts with time and some detail. I wanted to do something a bit differently because I already have mySQL installed.

as just a note I suspect my paths are different since I installed mySQL from a DMG versus brew. so I had to edit the compiler and linker settings to have the correct path settings.

compiler addition

linker addition

hope this helps that might run into problems that I had.

1 Like

alos trying to clear the version but still not updating the commands

i found the fix for Alex problem ( ie. stuck after postgres -D /usr/local/var/postgres`)
Dont try to quit or anything, just open a new terminal window and execute the commands in the new window (ie create db)

1 Like

One thing to note.

If you configure your Droplet the way it is one it in the screen cast it will break your CSS. Use the code below to fix this problem:

try drop.addProvider(VaporPostgreSQL.Provider.self)

There’s been a few updates since this screencast was created. Here are a few extra steps that I had to take to get the project running:

  1. No secrets folder under Config.
    Solution: Make your own secrets folder by using command + n while you’re in the Config folder.
  2. As @calebkleveter pointed out, you need to use try drop.addProvider(VaporPostgreSQL.Provider.self). Compiler now warns if you try to use the initializer that takes in providers.
1 Like

Thanks @kelvin_lau! :]

@dniswhite hi,
I think that I have the same problem (which is installing mysql from DMG and not from homebrew). I get errors with the package when I compile. my question is how did you edit the compiler and linker? I mean what exact steps should I take.

I had to change the project settings like I listed in my post.

unfortunately I found that really wasn’t the best option best every time you generate with vapor xcode you lose those settings and have to do it all over again. the best option is to remove mySQL and install via homebrew.

I just scrapped mySQL and left things the way they were and moved on with postgreSQL.

hi ray im having an issue when saving cant figure out the issue
thats the error im getting
“code”: 500,
“error”: true,
“message”: “The operation couldn’t be completed. (PostgreSQL.DatabaseError error 1.)”,
“metadata”: null

@rotemd1 Have you tried setting the user name and database name in the json file to your macOS user name, which is displayed in the Terminal ?

by the way, @rwenderlich. recently the entire screencast videos are not played in Safari 10.0.2. so I am using Chrome for the moment. is this happening only to me?

I just had a similar issue and resolved it.

First, what I initially did wrong is that I had added the wrong link into the Package.swift file. I put the driver in (GitHub - vapor-community/postgresql-driver: PostgreSQL driver for Fluent), and ran “vapor Xcode”. Then I corrected it but got “warning: refname ‘1.0.3’ is ambiguous.” errors.

Fetching Dependencies [Failed]
Error: warning: refname ‘1.0.0’ is ambiguous.
warning: refname ‘1.0.0’ is ambiguous.
warning: refname ‘1.0.5’ is ambiguous.
warning: refname ‘1.0.5’ is ambiguous.
swift-package: error: rename error: Directory not empty (66): /Users/ronanocsono/Documents/Code/PersonalProjects/vapor/HelloPersistance/Packages/postgresql-driver.git → /Users/ronanocsono/Documents/Code/PersonalProjects/vapor/HelloPersistance/Packages/FluentPostgreSQL-1.0.5

To fix it, cd into the Packages and “rm -rf” all those related to PostgreSQL:

rm -rf FluentPostgreSQL-1.0.5
rm -rf postgresql-provider
rm -rf postgresql-driver.git
rm -rf PostgreSQL-1.1.0
rm -rf CPostgreSQL-1.0.0

Then cd …/ and run “vapor xcode” again and it works.

Hi I installed postgresql using Homebrew. Command ‘postgres -D /usr/local/var/postgres’ results in an error I couldn’t solve for the past 3 days:
FATAL: postmaster became multithreaded during startup
HINT: Set the LC_ALL environment variable to a valid locale.
LOG: database system is shut down
After researching, I set the local variables in .bash_profile by adding these lines:
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
This was the only suggestion I could find on the Internet but it didn’t help, the error stayed the same (I tried restarting the computer after setting the variables, uninstalling and installing postgresql). I ran out of options, every kind of advice is really appreciated. The version is 9.6.3.

Hi Ray,

Nice Tutorial. An update to get things working:

.Package(url: “GitHub - vapor/vapor: 💧 A server-side Swift HTTP web framework.”, majorVersion: 2),
.Package(url: “GitHub - vapor-community/postgresql-provider: PostgreSQL Provider for the Vapor web framework.”, majorVersion: 2),
.Package(url: “GitHub - vapor-community/fluent-provider: A provider for including Fluent in Vapor applications”, majorVersion: 1)

import PostgreSQLProvider

private func setupProviders() throws {
try addProvider(FluentProvider.Provider.self)
try addProvider(PostgreSQLProvider.Provider.self)

import PostgreSQLProvider

get(“version”) {req in
let version = try self.postgresql().raw(“SELECT version()”);
return try JSON(node: version)

Config/postgresql.json. (not secret)
“hostname”: “”,
“user”: “whoami”, (current user)
“password”: “”,
“database”: “whoami”, (current database)
“port”: 5432

“driver”: “postgresql”,

And it works. Keep up the good work Ray!

1 Like

Thanks for sharing the updates! :]

Hi there guys… @rwenderlich this is my error when call localHost:8080/version:

[SQLite.StatusError: error(“no such function: version”)]
Conform ‘SQLite.StatusError’ to Debugging.Debuggable to provide more debug information.

And in the brower is error 500