From bfb2ff9390f0f79c90815bc7e03bd23fc62634a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 8 Dec 2016 16:02:35 +0100 Subject: [PATCH] Documentation --- GRDB/Core/Request.swift | 3 --- README.md | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/GRDB/Core/Request.swift b/GRDB/Core/Request.swift index 3e73f8bb4..32a77894b 100644 --- a/GRDB/Core/Request.swift +++ b/GRDB/Core/Request.swift @@ -1,8 +1,5 @@ /// The protocol for all types that define a way to fetch values from /// a database. -/// -/// TODO: show Type.fetchAll(db, request) -/// TODO: see also TypedRequest public protocol Request { /// A tuple that contains a prepared statement that is ready to be /// executed, and an eventual row adapter. diff --git a/README.md b/README.md index 5c0f07ae6..a76cf11b0 100644 --- a/README.md +++ b/README.md @@ -2555,7 +2555,7 @@ So don't miss the [SQL API](#sqlite-api). - [Fetching by Key](#fetching-by-key) - [Fetching Aggregated Values](#fetching-aggregated-values) - [Delete Requests](#delete-requests) -- [Request Protocols](#request-protocols) +- [Custom Requests](#custom-requests) - [GRDB Extension Guide](Documentation/ExtendingGRDB.md) @@ -3214,7 +3214,7 @@ Person.deleteOne(db, key: ["email": "arthur@example.com"]) ``` -## Request Protocols +## Custom Requests Until now, we have seen fetch requests created from any type that adopts the [TableMapping](#tablemapping-protocol) protocol: @@ -3250,22 +3250,22 @@ protocol TypedRequest : Request { } ``` -Request can not fetch itself, because it doesn't know what to fetch. But it can be consumed by fetchable types: +A Request doesn't know what to fetch, but it can be used by any fetchable type ([row](#fetching-rows), [value](#values), or [record](#records)): ```swift let request: Request = ... -try Row.fetchCursor(db, request) // DatabaseCursor -try Person.fetchAll(db, request) // [Person] -try String.fetchOne(db, request) // String? +try Row.fetchCursor(db, request) // DatabaseCursor +try Person.fetchAll(db, request) // [Person] +try String.fetchOne(db, request) // String? ``` -TypedRequest knows what to fetch, and thus it can fetch (just like [regular query interface requests](#requests)): +A TypedRequest improves over a plain Request because it knows what to fetch (just like [regular query interface requests](#requests)): ```swift -let request = ... // Some TypedRequest that fetches Person -try request.fetchCursor(db) // DatabaseCursor -try request.fetchAll() // [Person] -try request.fetchOne() // Person? +let request = ... // Some TypedRequest that fetches Person +try request.fetchCursor(db) // DatabaseCursor +try request.fetchAll() // [Person] +try request.fetchOne() // Person? ``` **To build fetch requests**, you can create your own type that adopts the protocols, or use one of the four built-in concrete types ([QueryInterfaceRequest](#requests), SQLRequest, AnyRequest, AnyTypedRequest):