StatementColumnConvertible

A type that can decode itself from the low-level C interface to SQLite results.

StatementColumnConvertible.swift:81
protocol StatementColumnConvertible
Browse conforming types

StatementColumnConvertible is adopted by Bool, Int, String, Date, and most common values.

When a type conforms to both DatabaseValueConvertible and StatementColumnConvertible, GRDB can apply some optimization whenever direct access to SQLite is possible. For example:

// Optimized
let scores = Int.fetchAll(db, sql: "SELECT score FROM player")

let rows = try Row.fetchCursor(db, sql: "SELECT * FROM player")
while let row = try rows.next() {
    // Optimized
    let int: Int = row[0]
    let name: String = row[1]
}

struct Player: FetchableRecord {
    var name: String
    var score: Int

    init(row: Row) {
        // Optimized
        name = row["name"]
        score = row["score"]
    }
}

To conform to StatementColumnConvertible, provide a custom implementation of init(sqliteStatement:index:). This implementation is ready-made for RawRepresentable types whose RawValue is StatementColumnConvertible.

Related SQLite documentation: https://www.sqlite.org/c3ref/column_blob.html

Creating a Value

Fetching Values from Raw SQL

Fetching Values from a Prepared Statement

Fetching Values from a Request

Supporting Types