From 84259fd9d8364d6a56496e57a3f4870ebfda99b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 8 Oct 2016 09:49:42 +0200 Subject: [PATCH] TableMapping.selectsRowID documentation --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 52f841453..6d7306b1f 100644 --- a/README.md +++ b/README.md @@ -2283,7 +2283,7 @@ try db.create(virtualTable: "books", using: FTS4()) { t in The implicit primary key is stored in the hidden column `rowid`. Hidden means that `SELECT *` does not select it, and yet it can be selected and queried: `SELECT *, rowid ... WHERE rowid = 1`. -**GRDB will automatically use this hidden column when your table has no explicit primary key:** +When possible, GRDB will automatically use this hidden column: ```swift // SELECT * FROM events WHERE rowid = 1 @@ -2296,9 +2296,13 @@ try Book.deleteOne(db, key: 1) ### Exposing the RowID Column -**Your record types that wrap a table without any explicit primary key don't know about the hidden rowid unless you tell them about it.** +**Your record types that wrap a table without any explicit primary key don't know about the hidden rowid.** -Making a record type fully aware of its rowid is a four-step process: +Without primary key, records don't have any identity, and the [persistence method](#persistence-methods) can behave in undesired fashion: `update` throws errors, `save` always performs insertions and may break constraints, `exists` is always false. + +When SQLite won't let you provide an explicit primary key (as in [full-text](#full-text-search) tables, for example), you may want to make your record type fully aware of the hidden rowid column. + +This is a three-step process: 1. Have the `selectsRowID` static property from the [TableMapping](#tablemapping-protocol) protocol return true.