Skip to content

Commit

Permalink
Another attempt at fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
photovirus committed Jul 4, 2024
1 parent 038307b commit a4e142f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Models+Content.swift
//
//
// Created by Yakov Shapovalov on 04.07.2024.
//

import Vapor

extension World: Content {}
17 changes: 7 additions & 10 deletions frameworks/Swift/vapor/vapor-swifql-ikiga/Sources/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension DatabaseIdentifier {


public func configure(_ app: Application) throws {
var decoder = IkigaJSONDecoder()
let decoder = IkigaJSONDecoder()
decoder.settings.dateDecodingStrategy = .iso8601
ContentConfiguration.global.use(decoder: decoder as ContentDecoder, for: .json)

Expand All @@ -51,19 +51,16 @@ public func routes(_ app: Application) throws {
["message": "Hello, world!"]
}

app.get("db") { req throws -> EventLoopFuture<World> in
req.postgres.connection(to: DbHost) { conn throws -> _ in
guard let world = try World
.select
app.get("db") { req async throws -> World in
guard let world = try await req.postgres.connection(to: .Db, { conn in
World.select
.where(\World.$id == Int.random(in: 1...10_000))
.execute(on: conn)
.first(decoding: World.self)
else {
throw Abort(.notFound)
}

return world
}).get() else {
throw Abort(.notFound)
}
return world
}

}
4 changes: 2 additions & 2 deletions frameworks/Swift/vapor/vapor-swifql-ikiga/Sources/json.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import IkigaJSON
import Vapor


extension IkigaJSONEncoder: ContentEncoder {
extension IkigaJSONEncoder: @retroactive ContentEncoder {
public func encode<E: Encodable>(
_ encodable: E,
to body: inout ByteBuffer,
Expand All @@ -29,7 +29,7 @@ extension IkigaJSONEncoder: ContentEncoder {
}
}

extension IkigaJSONDecoder: ContentDecoder {
extension IkigaJSONDecoder: @retroactive ContentDecoder {
public func decode<D: Decodable>(
_ decodable: D.Type,
from body: ByteBuffer,
Expand Down
15 changes: 10 additions & 5 deletions frameworks/Swift/vapor/vapor-swifql-ikiga/Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import PostgresBridge
import IkigaJSON
import Logging

var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)
@main
enum App {
static func main() throws {
var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)

let app = Application(env)
defer { app.shutdown() }
let app = Application(env)
defer { app.shutdown() }

try configure(app)
try configure(app)
}
}

0 comments on commit a4e142f

Please sign in to comment.