Server side Swift
Kitura
mkdir serverside
cd serverside/
mkdir server
cd server
docker run -itv $(pwd):/projects --name projects -w /projects -p 8089:8089 -p 8090:8090 -p 5984:5984 twostraws/server-side-swift /bin/bash
docker start projects
docker attach projects
root@c661e0faa890:/projects# mkdir project1
root@c661e0faa890:/projects# cd project1/
root@c661e0faa890:/projects/project1# swift package init --type executable
root@c661e0faa890:/projects/project1# swift build
root@c661e0faa890:/projects/project1# .build/debug/project1
Hello, world!
change package to:
let package = Package(
name: "project1",
dependencies: [
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1),
.Package(url: "https://github.com/IBM-Swift/HeliumLogger.git", majorVersion: 1),
.Package(url: "https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git", majorVersion: 1)
]
)
swift build
swift package generate-xcodeproj
docker ps - shows a list of running containers
docker ps -a shows list all projects
docker start #NAME PROJ#
docker attach #NAME#
ctrl-p ctrl-q to get back to local terminal without stopping
docker start -i #NAME#
Vapor
Use & adjust Post template.
change in fluent.json
"driver":"memory" into "driver":"sqlite"
create
sqlite.json
insert
{
"path":"pokemonDB.sqlite"
}
in config+Setup
change setupPreparations into desired Pokemon class
private func setupPreparations() throws {
preparations.append(Post.self)
preparations.append(Pokemon.self)
}
in router
get("version"){
request in
let result = try Pokemon.database?.driver.raw("select sqlite_version();")
return try JSON(node: result)
}
MySql
start mysql server
docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest