Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save niklassaers/ece353ee80add93ab63f9cd110f0b4b2 to your computer and use it in GitHub Desktop.
Save niklassaers/ece353ee80add93ab63f9cd110f0b4b2 to your computer and use it in GitHub Desktop.
Vapor with Theo - Getting started
import Vapor
import Theo
func theoClient(completion: @escaping (BoltClient) -> ()) {
do {
let client = try BoltClient(hostname: "127.0.0.1",
port: 7687,
username: "neo4j",
password: "test",
encrypted: true)
client.connect { result in
let isSuccess = try! result.get()
assert(isSuccess)
completion(client)
}
} catch {
print("Error! \(String(describing: error))")
}
}
func routes(_ app: Application) throws {
app.get { req -> EventLoopFuture<String> in
let promise: EventLoopPromise<String> = req.eventLoop.makePromise()
theoClient() { theo in
let newNode = Node(label: "New", properties: [ "createdTime": Date().timeIntervalSince1970 ])
theo.createAndReturnNode(node: newNode) { result in
do {
let node = try result.get()
assert(node.labels.first! == "New")
promise.completeWith(.success("Newly created node!"))
} catch {
promise.completeWith(.failure(error))
}
}
}
return promise.futureResult
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment