FetchableRecord

A type that can decode itself from a database row.

FetchableRecord.swift:104
protocol FetchableRecord
Browse conforming types

To conform to FetchableRecord, provide an implementation for the init(row:) initializer. This implementation is ready-made for Decodable types.

For example:

struct Player: FetchableRecord, Decodable {
    var name: String
    var score: Int
}

if let row = try Row.fetchOne(db, sql: "SELECT * FROM player") {
    let player = try Player(row: row)
}

If you add conformance to TableRecord, the record type can generate SQL queries for you:

struct Player: FetchableRecord, TableRecord, Decodable {
    var name: String
    var score: Int
}

let players = try Player.fetchAll(db)
let players = try Player.order(Column("score")).fetchAll(db)

Initializers

Fetching Records

Fetching Records from Raw SQL

Fetching Records from a Prepared Statement

Fetching Records from a Request

Fetching Records by Primary Key

Fetching Record by Key

Configuring Row Decoding for the Standard Decodable Protocol

Supporting Types