Swiftpack.co -  Package - vapor/fluent-kit
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
vapor/fluent-kit
Swift ORM (queries, models, and relations) for NoSQL and SQL databases
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.11.0")

FluentKit

Documentation Team Chat MIT License Continuous Integration Swift 5.2

GitHub

link
Stars: 84
Last commit: 2 weeks ago

Release Notes

Add @OptionalChild property wrapper (one-to-one relation)
5 weeks ago
This patch was authored by @fananek and released by @gwynne.

Add new @OptionalChild property for one-to-one relations.

Example:

private final class Planet: Model {
    static let schema = "planets"

    @ID(key: .id)
    var id: UUID?

    @Field(key: "name")
    var name: String

    @OptionalChild(for: \.$planet)
    var governor: Governor

    init() { }

    init(id: IDValue? = nil, name: String) {
        self.id = id
        self.name = name
    }
}

private final class Governor: Model {
    static let schema = "governors"

    @ID(key: .id)
    var id: UUID?

    @Field(key: "name")
    var name: String

    @Parent(key: "planet_id")
    var planet: Planet

    init() { }

    init(id: IDValue? = nil, name: String, planetID: UUID) {
        self.id = id
        self.name = name
        self.$planet.id = planetID
    }
}

See test files ChildTests.swift and Governor.swift for more details.

This PR:

  • Closes issue #74
  • Supersedes #394 (which seems to be inactive)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco