From 4409b07ef5db6d3fc513fa7415ec007f484d4678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 23 Apr 2018 08:39:19 +0200 Subject: [PATCH] ColumnExpression documentation --- GRDB/QueryInterface/Column.swift | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/GRDB/QueryInterface/Column.swift b/GRDB/QueryInterface/Column.swift index bdad2d1d8..cd6ecb5c0 100644 --- a/GRDB/QueryInterface/Column.swift +++ b/GRDB/QueryInterface/Column.swift @@ -1,4 +1,23 @@ -/// The protocol for types that define database columns +/// Adopt the ColumnExpression protocol in order to define a custom column type. +/// +/// You can, for example, define a String-based column enum: +/// +/// enum Columns: String, ColumnExpression { +/// case id, name, score +/// } +/// let nameColumn = Columns.name +/// let arthur = try Player.filter(nameColumn == "Arthur").fetchOne(db) +/// +/// You can also define a genuine column type: +/// +/// struct MyColumn: ColumnExpression { +/// var name: String +/// var sqlType: String +/// } +/// let nameColumn = MyColumn(name: "name", sqlType: "VARCHAR") +/// let arthur = try Player.filter(nameColumn == "Arthur").fetchOne(db) +/// +/// See https://github.com/groue/GRDB.swift#the-query-interface public protocol ColumnExpression: SQLExpression { /// The unqualified name of a database column. /// @@ -20,7 +39,10 @@ extension ColumnExpression { } } -/// A column in a database table +/// A column in a database table. +/// +/// When you need to introduce your own column type, don't wrap a Column. +/// Instead, adopt the ColumnExpression protocol. /// /// See https://github.com/groue/GRDB.swift#the-query-interface public struct Column: ColumnExpression {