Closed martinlasek closed 6 years ago
A request to the database completes
A request to the database never completes
vapor new brokenPSQL --template=api --branch=beta
Package.swift
let package = Package( name: "psqlSaveIsHanging", dependencies: [ .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-beta"), .package(url: "https://github.com/vapor/fluent.git", from: "3.0.0-beta"), .package(url: "https://github.com/vapor/fluent-postgresql.git", from: "1.0.0-beta") ], targets: [ .target(name: "App", dependencies: ["FluentSQLite", "FluentPostgreSQL", "Vapor"]), .target(name: "Run", dependencies: ["App"]), .testTarget(name: "AppTests", dependencies: ["App"]) ] )
swift package generate-xcodeproj
Todo
PostgreSQLModel
import FluentSQLite import Vapor import FluentPostgreSQL /// A single entry of a Todo list. final class Todo: PostgreSQLModel { ... } ...
configure.swift
import FluentPostgreSQL import Foundation import PostgreSQL import Vapor public func configure( _ config: inout Config, _ env: inout Environment, _ services: inout Services ) throws { // Register providers first try services.register(FluentPostgreSQLProvider()) // Register routes to the router let router = EngineRouter.default() try routes(router) services.register(router, as: Router.self) // Configure a PostgrSQL database var databases = DatabaseConfig() let databaseConfig = PostgreSQLDatabaseConfig( hostname: "127.0.0.1", port: 5432, username: "yourUserName", database: "yourDatabaseName", password: nil ) databases.add(database: PostgreSQLDatabase(config: databaseConfig), as: .psql) services.register(databases) // Configure migrations var migrations = MigrationConfig() migrations.add(model: Todo.self, database: .psql) services.register(migrations) }
http://127.0.0.1:8080/todos
All you see is the site loads forever.
Seeing this as well!
@tanner0101 wrote: " You can get around it with:
req.withPooledConnection(to: .psql) { conn in ... }
instead of using the request directly as your DatabaseConnectable"
on slack.
Expected Behavior
A request to the database completes
Current Behavior
A request to the database never completes
How to reproduce
1. create a new project
2. add FluentPostgreSQL as a dependencyin
Package.swift
3. fetch dependencies + create xcode project
4. open project and adjust
Todo
Model to conform toPostgreSQLModel
5. Set PostgreSQL as your database within
configure.swift
5. run the project and visit the site
http://127.0.0.1:8080/todos
All you see is the site loads forever.