mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
DocC: document extensions
This commit is contained in:
1 parent
284a4ee1ac
commit
60beb7cd9c
17 files changed
+329
-132
No files matched your search
+188
-77
@@ -14,9 +14,14 @@
|
||||
extension RangeReplaceableCollection {
|
||||
/// Creates a collection containing the elements of a cursor.
|
||||
///
|
||||
/// // [String]
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Array(cursor)
|
||||
/// For example, you can turn a cursor of strings into an array
|
||||
/// of strings:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a [String]
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Array(cursor)
|
||||
/// ```
|
||||
///
|
||||
/// - parameter cursor: The cursor whose elements feed the collection.
|
||||
public init(_ cursor: some Cursor<Element>) throws {
|
||||
@@ -26,9 +31,14 @@ extension RangeReplaceableCollection {
|
||||
|
||||
/// Creates a collection containing the elements of a cursor.
|
||||
///
|
||||
/// // [String]
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Array(cursor, minimumCapacity: 100)
|
||||
/// For example, you can turn a cursor of strings into an array
|
||||
/// of strings:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a [String]
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Array(cursor, minimumCapacity: 100)
|
||||
/// ```
|
||||
///
|
||||
/// - parameter cursor: The cursor whose elements feed the collection.
|
||||
/// - parameter minimumCapacity: Prepares the returned collection to store
|
||||
@@ -41,8 +51,8 @@ extension RangeReplaceableCollection {
|
||||
|
||||
/// Adds the elements of a cursor to the end of this collection.
|
||||
///
|
||||
/// In case of error, an unspecified amount of elements have been added to
|
||||
/// the collection.
|
||||
/// - Important: If an error is thrown, an unspecified amount of
|
||||
/// elements have been added to the collection.
|
||||
///
|
||||
/// - parameter newElements: The elements to append to the collection.
|
||||
public mutating func append(contentsOf newElements: some Cursor<Element>) throws {
|
||||
@@ -58,9 +68,13 @@ extension Dictionary {
|
||||
/// given closure and whose values are arrays of the elements that returned
|
||||
/// each key.
|
||||
///
|
||||
/// // [Int64: [Player]]
|
||||
/// let cursor = try Player.fetchCursor(db)
|
||||
/// let dictionary = try Dictionary(grouping: cursor, by: { $0.teamID })
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a [Int64: [Player]]
|
||||
/// let cursor = try Player.fetchCursor(db)
|
||||
/// let dictionary = try Dictionary(grouping: cursor, by: { $0.teamID })
|
||||
/// ```
|
||||
///
|
||||
/// - parameter cursor: A cursor of values to group into a dictionary.
|
||||
/// - parameter keyForValue: A closure that returns a key for each element
|
||||
@@ -81,12 +95,16 @@ extension Dictionary {
|
||||
/// given closure and whose values are arrays of the elements that returned
|
||||
/// each key.
|
||||
///
|
||||
/// // [Int64: [Player]]
|
||||
/// let cursor = try Player.fetchCursor(db)
|
||||
/// let dictionary = try Dictionary(
|
||||
/// minimumCapacity: 100,
|
||||
/// grouping: cursor,
|
||||
/// by: { $0.teamID })
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a [Int64: [Player]]
|
||||
/// let cursor = try Player.fetchCursor(db)
|
||||
/// let dictionary = try Dictionary(
|
||||
/// minimumCapacity: 100,
|
||||
/// grouping: cursor,
|
||||
/// by: { $0.teamID })
|
||||
/// ```
|
||||
///
|
||||
/// - parameter minimumCapacity: The minimum number of key-value pairs that
|
||||
/// the newly created dictionary should be able to store without
|
||||
@@ -112,9 +130,13 @@ extension Dictionary {
|
||||
/// of key-value tuples with unique keys. Passing a cursor with duplicate
|
||||
/// keys to this initializer results in a fatal error.
|
||||
///
|
||||
/// // [Int64: Player]
|
||||
/// let cursor = try Player.fetchCursor(db).map { ($0.id, $0) }
|
||||
/// let playerByID = try Dictionary(uniqueKeysWithValues: cursor)
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a [Int64: [Player]]
|
||||
/// let cursor = try Player.fetchCursor(db).map { ($0.id, $0) }
|
||||
/// let playerByID = try Dictionary(uniqueKeysWithValues: cursor)
|
||||
/// ```
|
||||
///
|
||||
/// - parameter keysAndValues: A cursor of key-value pairs to use for the
|
||||
/// new dictionary. Every key in `keysAndValues` must be unique.
|
||||
@@ -137,11 +159,15 @@ extension Dictionary {
|
||||
/// of key-value tuples with unique keys. Passing a cursor with duplicate
|
||||
/// keys to this initializer results in a fatal error.
|
||||
///
|
||||
/// // [Int64: Player]
|
||||
/// let cursor = try Player.fetchCursor(db).map { ($0.id, $0) }
|
||||
/// let playerByID = try Dictionary(
|
||||
/// minimumCapacity: 100,
|
||||
/// uniqueKeysWithValues: cursor)
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a [Int64: [Player]]
|
||||
/// let cursor = try Player.fetchCursor(db).map { ($0.id, $0) }
|
||||
/// let playerByID = try Dictionary(
|
||||
/// minimumCapacity: 100,
|
||||
/// uniqueKeysWithValues: cursor)
|
||||
/// ```
|
||||
///
|
||||
/// - parameter minimumCapacity: The minimum number of key-value pairs that
|
||||
/// the newly created dictionary should be able to store without
|
||||
@@ -165,9 +191,13 @@ extension Dictionary {
|
||||
extension Set {
|
||||
/// Creates a set containing the elements of a cursor.
|
||||
///
|
||||
/// // Set<String>
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Set(cursor)
|
||||
/// For example, you can turn a cursor of strings into a set of strings:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a Set<String>
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Set(cursor)
|
||||
/// ```
|
||||
///
|
||||
/// - parameter cursor: A cursor of values to gather into a set.
|
||||
public init(_ cursor: some Cursor<Element>) throws {
|
||||
@@ -180,9 +210,13 @@ extension Set {
|
||||
|
||||
/// Creates a set containing the elements of a cursor.
|
||||
///
|
||||
/// // Set<String>
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Set(cursor, minimumCapacity: 100)
|
||||
/// For example, you can turn a cursor of strings into a set of strings:
|
||||
///
|
||||
/// ```swift
|
||||
/// // Create a Set<String>
|
||||
/// let cursor = try String.fetchCursor(db, ...)
|
||||
/// let strings = try Set(cursor, minimumCapacity: 100)
|
||||
/// ```
|
||||
///
|
||||
/// - parameter cursor: A cursor of values to gather into a set.
|
||||
/// - parameter minimumCapacity: The minimum number of elements that the
|
||||
@@ -240,6 +274,75 @@ extension Sequence {
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Iterating Over a Cursor’s Elements
|
||||
///
|
||||
/// - ``next()``
|
||||
/// - ``forEach(_:)-4ib2m``
|
||||
/// - ``enumerated()``
|
||||
/// - ``isEmpty``
|
||||
///
|
||||
/// ### Finding Elements
|
||||
///
|
||||
/// - ``contains(_:)``
|
||||
/// - ``contains(where:)``
|
||||
/// - ``first(where:)``
|
||||
/// - ``min()``
|
||||
/// - ``min(by:)``
|
||||
/// - ``max()``
|
||||
/// - ``max(by:)``
|
||||
///
|
||||
/// ### Selecting Elements
|
||||
///
|
||||
/// - ``prefix(_:)``
|
||||
/// - ``prefix(while:)``
|
||||
/// - ``suffix(_:)``
|
||||
///
|
||||
/// ### Excluding Elements
|
||||
///
|
||||
/// - ``dropFirst()``
|
||||
/// - ``dropFirst(_:)``
|
||||
/// - ``dropLast()``
|
||||
/// - ``dropLast(_:)``
|
||||
/// - ``drop(while:)``
|
||||
/// - ``filter(_:)``
|
||||
///
|
||||
/// ### Transforming a Cursor
|
||||
///
|
||||
/// - ``map(_:)``
|
||||
/// - ``compactMap(_:)``
|
||||
/// - ``flatMap(_:)-5ci2v``
|
||||
/// - ``flatMap(_:)-8jxlj``
|
||||
/// - ``reduce(_:_:)``
|
||||
/// - ``reduce(into:_:)``
|
||||
///
|
||||
/// ### Transforming a Sequence into a Cursor
|
||||
///
|
||||
/// - ``Swift/Sequence/flatMap(_:)``
|
||||
///
|
||||
/// ### Joining Elements
|
||||
///
|
||||
/// - ``joined()-5r5ja``
|
||||
/// - ``joined()-7bnrx``
|
||||
/// - ``joined(separator:)``
|
||||
///
|
||||
/// ### Filling RangeReplaceableCollection with the contents of a Cursor
|
||||
///
|
||||
/// - ``Swift/RangeReplaceableCollection/init(_:)``
|
||||
/// - ``Swift/RangeReplaceableCollection/init(_:minimumCapacity:)``
|
||||
/// - ``Swift/RangeReplaceableCollection/append(contentsOf:)``
|
||||
///
|
||||
/// ### Creating a Dictionary from the contents of a Cursor
|
||||
///
|
||||
/// - ``Swift/Dictionary/init(grouping:by:)``
|
||||
/// - ``Swift/Dictionary/init(minimumCapacity:grouping:by:)``
|
||||
/// - ``Swift/Dictionary/init(uniqueKeysWithValues:)``
|
||||
/// - ``Swift/Dictionary/init(minimumCapacity:uniqueKeysWithValues:)``
|
||||
///
|
||||
/// ### Creating a Set from the contents of a Cursor
|
||||
///
|
||||
/// - ``Swift/Set/init(_:)``
|
||||
/// - ``Swift/Set/init(_:minimumCapacity:)``
|
||||
///
|
||||
/// ### Supporting Types
|
||||
///
|
||||
/// - ``AnyCursor``
|
||||
@@ -269,7 +372,7 @@ extension Cursor {
|
||||
/// Returns a Boolean value indicating whether the cursor does not contain
|
||||
/// any element.
|
||||
///
|
||||
/// - important: This property may consume elements.
|
||||
/// - important: This property consumes an element.
|
||||
public var isEmpty: Bool {
|
||||
get throws { try next() == nil }
|
||||
}
|
||||
@@ -294,13 +397,17 @@ extension Cursor {
|
||||
/// Returns a cursor of pairs (n, x), where n represents a consecutive
|
||||
/// integer starting at zero, and x represents an element of the cursor.
|
||||
///
|
||||
/// let cursor = try String.fetchCursor(db, sql: "SELECT 'foo' UNION ALL SELECT 'bar'")
|
||||
/// let c = cursor.enumerated()
|
||||
/// while let (n, x) = c.next() {
|
||||
/// print("\(n): \(x)")
|
||||
/// }
|
||||
/// // Prints: "0: foo"
|
||||
/// // Prints: "1: bar"
|
||||
/// ```swift
|
||||
/// let cursor = try String.fetchCursor(db, sql: """
|
||||
/// SELECT 'foo' UNION ALL SELECT 'bar'
|
||||
/// """)
|
||||
/// let c = cursor.enumerated()
|
||||
/// while let (n, x) = c.next() {
|
||||
/// print("\(n): \(x)")
|
||||
/// }
|
||||
/// // Prints: "0: foo"
|
||||
/// // Prints: "1: bar"
|
||||
/// ```
|
||||
public func enumerated() -> EnumeratedCursor<Self> {
|
||||
EnumeratedCursor(self)
|
||||
}
|
||||
@@ -346,11 +453,13 @@ extension Cursor {
|
||||
/// If the number of elements to drop exceeds the number of elements in
|
||||
/// the cursor, the result is an empty cursor.
|
||||
///
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropFirst(2))
|
||||
/// // Prints "[3, 4, 5]"
|
||||
/// try print(numbers.dropFirst(10))
|
||||
/// // Prints "[]"
|
||||
/// ```swift
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropFirst(2))
|
||||
/// // Prints "[3, 4, 5]"
|
||||
/// try print(numbers.dropFirst(10))
|
||||
/// // Prints "[]"
|
||||
/// ```
|
||||
///
|
||||
/// - Parameter n: The number of elements to drop from the beginning of
|
||||
/// the cursor. `n` must be greater than or equal to zero.
|
||||
@@ -364,9 +473,11 @@ extension Cursor {
|
||||
///
|
||||
/// The following example drops the first element from a cursor of integers.
|
||||
///
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropFirst())
|
||||
/// // Prints "[2, 3, 4, 5]"
|
||||
/// ```swift
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropFirst())
|
||||
/// // Prints "[2, 3, 4, 5]"
|
||||
/// ```
|
||||
///
|
||||
/// If the cursor has no elements, the result is an empty cursor.
|
||||
///
|
||||
@@ -381,11 +492,13 @@ extension Cursor {
|
||||
/// The cursor must be finite. If the number of elements to drop exceeds
|
||||
/// the number of elements in the cursor, the result is an empty array.
|
||||
///
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropLast(2))
|
||||
/// // Prints "[1, 2, 3]"
|
||||
/// try print(numbers.dropLast(10))
|
||||
/// // Prints "[]"
|
||||
/// ```swift
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropLast(2))
|
||||
/// // Prints "[1, 2, 3]"
|
||||
/// try print(numbers.dropLast(10))
|
||||
/// // Prints "[]"
|
||||
/// ```
|
||||
///
|
||||
/// - Parameter n: The number of elements to drop off the end of the
|
||||
/// cursor. `n` must be greater than or equal to zero.
|
||||
@@ -414,9 +527,11 @@ extension Cursor {
|
||||
///
|
||||
/// The following example drops the last element from a cursor of integers.
|
||||
///
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropLast())
|
||||
/// // Prints "[1, 2, 3, 4]"
|
||||
/// ```swift
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.dropLast())
|
||||
/// // Prints "[1, 2, 3, 4]"
|
||||
/// ```
|
||||
///
|
||||
/// If the cursor has no elements, the result is an empty cursor.
|
||||
///
|
||||
@@ -502,11 +617,13 @@ extension Cursor {
|
||||
/// If the maximum length exceeds the number of elements in the cursor,
|
||||
/// the result contains all the elements in the cursor.
|
||||
///
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.prefix(2))
|
||||
/// // Prints "[1, 2]"
|
||||
/// try print(numbers.prefix(10))
|
||||
/// // Prints "[1, 2, 3, 4, 5]"
|
||||
/// ```swift
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.prefix(2))
|
||||
/// // Prints "[1, 2]"
|
||||
/// try print(numbers.prefix(10))
|
||||
/// // Prints "[1, 2, 3, 4, 5]"
|
||||
/// ```
|
||||
///
|
||||
/// - Parameter maxLength: The maximum number of elements to return. The
|
||||
/// value of `maxLength` must be greater than or equal to zero.
|
||||
@@ -562,11 +679,13 @@ extension Cursor {
|
||||
/// elements in the cursor, the result contains all the elements in the
|
||||
/// cursor.
|
||||
///
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.suffix(2))
|
||||
/// // Prints "[4, 5]"
|
||||
/// try print(numbers.suffix(10))
|
||||
/// // Prints "[1, 2, 3, 4, 5]"
|
||||
/// ```swift
|
||||
/// let numbers = AnyCursor([1, 2, 3, 4, 5])
|
||||
/// try print(numbers.suffix(2))
|
||||
/// // Prints "[4, 5]"
|
||||
/// try print(numbers.suffix(10))
|
||||
/// // Prints "[1, 2, 3, 4, 5]"
|
||||
/// ```
|
||||
///
|
||||
/// - Parameter maxLength: The maximum number of elements to return. The
|
||||
/// value of `maxLength` must be greater than or equal to zero.
|
||||
@@ -620,24 +739,16 @@ extension Cursor where Element: Equatable {
|
||||
extension Cursor where Element: Comparable {
|
||||
/// Returns the maximum element in the cursor.
|
||||
///
|
||||
/// - Parameter areInIncreasingOrder: A predicate that returns `true`
|
||||
/// if its first argument should be ordered before its second
|
||||
/// argument; otherwise, `false`.
|
||||
/// - Returns: The cursor's maximum element, according to
|
||||
/// `areInIncreasingOrder`. If the cursor has no elements, returns
|
||||
/// `nil`.
|
||||
/// - Returns: The cursor's maximum element. If the cursor has no
|
||||
/// elements, returns `nil`.
|
||||
public func max() throws -> Element? {
|
||||
try max(by: <)
|
||||
}
|
||||
|
||||
/// Returns the minimum element in the cursor.
|
||||
///
|
||||
/// - Parameter areInIncreasingOrder: A predicate that returns `true`
|
||||
/// if its first argument should be ordered before its second
|
||||
/// argument; otherwise, `false`.
|
||||
/// - Returns: The cursor's minimum element, according to
|
||||
/// `areInIncreasingOrder`. If the cursor has no elements, returns
|
||||
/// `nil`.
|
||||
/// - Returns: The cursor's minimum element. If the cursor has no
|
||||
/// elements, returns `nil`.
|
||||
public func min() throws -> Element? {
|
||||
try min(by: <)
|
||||
}
|
||||
|
||||
+5
-3
@@ -39,6 +39,8 @@
|
||||
///
|
||||
/// - ``append(literal:)``
|
||||
/// - ``append(sql:arguments:)``
|
||||
/// - ``Swift/Collection/joined(separator:)``
|
||||
/// - ``Swift/Sequence/joined(separator:)``
|
||||
public struct SQL {
|
||||
/// `SQL.Element` is a component of an `SQL` literal.
|
||||
///
|
||||
@@ -316,12 +318,12 @@ extension SQL: SQLOrderingTerm {
|
||||
}
|
||||
|
||||
extension Sequence where Element == SQL {
|
||||
/// Returns the concatenated `SQL` literal of this sequence of literals,
|
||||
/// Concatenates the sequence elements into a new `SQL` literal,
|
||||
/// inserting the given raw SQL separator between each element.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```
|
||||
/// ```swift
|
||||
/// let components: [SQL] = [
|
||||
/// "UPDATE player",
|
||||
/// "SET name = \(name)",
|
||||
@@ -341,7 +343,7 @@ extension Sequence where Element == SQL {
|
||||
}
|
||||
|
||||
extension Collection where Element == SQL {
|
||||
/// Returns the concatenated `SQL` literal of this collection of literals,
|
||||
/// Concatenates the collection elements into a new `SQL` literal,
|
||||
/// inserting the given raw SQL separator between each element.
|
||||
///
|
||||
/// For example:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if canImport(CoreGraphics)
|
||||
import CoreGraphics
|
||||
|
||||
/// CGFloat adopts DatabaseValueConvertible
|
||||
/// `CGFloat` is a database value.
|
||||
extension CGFloat: DatabaseValueConvertible {
|
||||
/// Returns a REAL database value.
|
||||
public var databaseValue: DatabaseValue {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// Data is convertible to and from DatabaseValue.
|
||||
/// `Data` is a database value.
|
||||
extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
public init(sqliteStatement: SQLiteStatement, index: CInt) {
|
||||
if let bytes = sqlite3_column_blob(sqliteStatement, index) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
#if !os(Linux)
|
||||
/// NSDate is stored in the database using the format
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
/// `NSDate` is a database value.
|
||||
extension NSDate: DatabaseValueConvertible {
|
||||
/// Returns a TEXT database value that contains the date encoded as
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
@@ -31,8 +30,6 @@ extension NSDate: DatabaseValueConvertible {
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Date is stored in the database using the format
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
extension Date: DatabaseValueConvertible {
|
||||
/// Returns a TEXT database value that contains the date encoded as
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
@@ -115,6 +112,7 @@ extension Date: DatabaseValueConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// `Date` is a database value.
|
||||
extension Date: StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if !os(Linux)
|
||||
import Foundation
|
||||
|
||||
/// Decimal adopts DatabaseValueConvertible
|
||||
/// `Decimal` is a database value.
|
||||
extension Decimal: DatabaseValueConvertible {
|
||||
/// Returns a TEXT decimal value.
|
||||
public var databaseValue: DatabaseValue {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if !os(Linux)
|
||||
import Foundation
|
||||
|
||||
/// NSData is convertible to and from DatabaseValue.
|
||||
/// `NSData` is a database value.
|
||||
extension NSData: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a BLOB database value.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// NSNull adopts DatabaseValueConvertible
|
||||
/// `NSDate` is a database value.
|
||||
extension NSNull: DatabaseValueConvertible {
|
||||
|
||||
/// Returns the NULL database value.
|
||||
|
||||
@@ -9,7 +9,7 @@ private let integerRoundingBehavior = NSDecimalNumberHandler(
|
||||
raiseOnUnderflow: false,
|
||||
raiseOnDivideByZero: false)
|
||||
|
||||
/// NSNumber adopts DatabaseValueConvertible
|
||||
/// `NSNumber` is a database value.
|
||||
extension NSNumber: DatabaseValueConvertible {
|
||||
|
||||
/// A database value.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if !os(Linux)
|
||||
import Foundation
|
||||
|
||||
/// NSString adopts DatabaseValueConvertible
|
||||
/// `NSString` is a database value.
|
||||
extension NSString: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a TEXT database value.
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import Foundation
|
||||
|
||||
#if !os(Linux)
|
||||
/// NSURL stores its absoluteString in the database.
|
||||
/// `NSURL` is a database value.
|
||||
///
|
||||
/// `NSURL` stores its `absoluteString` in the database.
|
||||
extension NSURL: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a TEXT database value containing the absolute URL.
|
||||
@@ -18,5 +20,7 @@ extension NSURL: DatabaseValueConvertible {
|
||||
}
|
||||
#endif
|
||||
|
||||
/// URL stores its absoluteString in the database.
|
||||
/// `URL` is a database value.
|
||||
///
|
||||
/// `URL` stores its `absoluteString` in the database.
|
||||
extension URL: DatabaseValueConvertible { }
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
#if !os(Linux)
|
||||
/// NSUUID adopts DatabaseValueConvertible
|
||||
/// `NSUUID` is a database value.
|
||||
extension NSUUID: DatabaseValueConvertible {
|
||||
/// Returns a BLOB database value containing the uuid bytes.
|
||||
public var databaseValue: DatabaseValue {
|
||||
@@ -35,7 +35,7 @@ extension NSUUID: DatabaseValueConvertible {
|
||||
}
|
||||
#endif
|
||||
|
||||
/// UUID adopts DatabaseValueConvertible
|
||||
/// `UUID` is a database value.
|
||||
extension UUID: DatabaseValueConvertible {
|
||||
/// Returns a BLOB database value containing the uuid bytes.
|
||||
public var databaseValue: DatabaseValue {
|
||||
|
||||
@@ -44,6 +44,7 @@ extension Optional: SQLSelectable where Wrapped: SQLSelectable {
|
||||
|
||||
extension Optional: SQLSpecificExpressible where Wrapped: SQLSpecificExpressible { }
|
||||
|
||||
/// `Optional` is a database value when it wrapped type is.
|
||||
extension Optional: DatabaseValueConvertible where Wrapped: DatabaseValueConvertible {
|
||||
public var databaseValue: DatabaseValue {
|
||||
switch self {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// MARK: - Value Types
|
||||
|
||||
/// Bool adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Bool` is a database value.
|
||||
extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -95,7 +95,7 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Int adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Int` is a database value.
|
||||
extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -134,7 +134,7 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Int8 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Int8` is a database value.
|
||||
extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -173,7 +173,7 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Int16 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Int16` is a database value.
|
||||
extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -212,7 +212,7 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Int32 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Int32` is a database value.
|
||||
extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -251,7 +251,7 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Int64 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Int64` is a database value.
|
||||
extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -294,7 +294,7 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// UInt adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `UInt` is a database value.
|
||||
extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -333,7 +333,7 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// UInt8 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `UInt8` is a database value.
|
||||
extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -372,7 +372,7 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// UInt16 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `UInt16` is a database value.
|
||||
extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -411,7 +411,7 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// UInt32 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `UInt32` is a database value.
|
||||
extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -450,7 +450,7 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// UInt64 adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `UInt64` is a database value.
|
||||
extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -489,7 +489,7 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Double adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Double` is a database value.
|
||||
extension Double: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -529,7 +529,7 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Float adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `Float` is a database value.
|
||||
extension Float: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
@@ -569,7 +569,7 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// String adopts DatabaseValueConvertible and StatementColumnConvertible.
|
||||
/// `String` is a database value.
|
||||
extension String: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
|
||||
@@ -165,6 +165,38 @@ This extra conformance is not required: only aim at the low-level C interface if
|
||||
- ``fetchSet(_:_:)-1foke``
|
||||
- ``fetchOne(_:_:)-o6yj``
|
||||
|
||||
### Supported Value Types
|
||||
|
||||
- ``Swift/Bool``
|
||||
- ``CoreFoundation/CGFloat``
|
||||
- ``Foundation/Data``
|
||||
- ``DatabaseDateComponents``
|
||||
- ``Foundation/Date``
|
||||
- ``Swift/Double``
|
||||
- ``Foundation/Decimal``
|
||||
- ``Swift/Float``
|
||||
- ``Swift/Int``
|
||||
- ``Swift/Int8``
|
||||
- ``Swift/Int16``
|
||||
- ``Swift/Int32``
|
||||
- ``Swift/Int64``
|
||||
- ``Foundation/NSData``
|
||||
- ``Foundation/NSDate``
|
||||
- ``Foundation/NSNull``
|
||||
- ``Foundation/NSNumber``
|
||||
- ``Foundation/NSString``
|
||||
- ``Foundation/NSURL``
|
||||
- ``Foundation/NSUUID``
|
||||
- ``Swift/Optional``
|
||||
- ``Swift/UInt``
|
||||
- ``Swift/UInt8``
|
||||
- ``Swift/UInt16``
|
||||
- ``Swift/UInt32``
|
||||
- ``Swift/UInt64``
|
||||
- ``Swift/String``
|
||||
- ``Foundation/URL``
|
||||
- ``Foundation/UUID``
|
||||
|
||||
### Supporting Types
|
||||
|
||||
- ``DatabaseValueCursor``
|
||||
|
||||
@@ -81,7 +81,6 @@ For a more detailed overview, see [SQLite API](https://github.com/groue/GRDB.swi
|
||||
|
||||
### Database Values
|
||||
|
||||
- ``DatabaseDateComponents``
|
||||
- ``DatabaseValueConvertible``
|
||||
- ``StatementColumnConvertible``
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ public struct SQLExpression {
|
||||
|
||||
/// An associative binary SQL operator, such as `+`, `*`, `AND`, etc.
|
||||
///
|
||||
/// Use it with the `joined(operator:)` method. For example:
|
||||
/// Use an associative operator with the `joined(operator:)` method:
|
||||
///
|
||||
/// ```swift
|
||||
/// // SELECT score + bonus + 1000 FROM player
|
||||
@@ -206,6 +206,27 @@ public struct SQLExpression {
|
||||
/// 1000.databaseValue]
|
||||
/// let request = Player.select(values.joined(operator: .add))
|
||||
/// ```
|
||||
///
|
||||
/// ## Topics
|
||||
///
|
||||
/// ### Arithmetic Operators
|
||||
///
|
||||
/// - ``add``
|
||||
/// - ``multiply``
|
||||
///
|
||||
/// ### Logical Operators
|
||||
///
|
||||
/// - ``and``
|
||||
/// - ``or``
|
||||
///
|
||||
/// ### String Operators
|
||||
///
|
||||
/// - ``concat``
|
||||
///
|
||||
/// ### Bitwise Operators
|
||||
///
|
||||
/// - ``bitwiseAnd``
|
||||
/// - ``bitwiseOr``
|
||||
public struct AssociativeBinaryOperator: Hashable {
|
||||
/// The SQL operator
|
||||
let sql: String
|
||||
@@ -237,7 +258,7 @@ public struct SQLExpression {
|
||||
self.isBijective = bijective
|
||||
}
|
||||
|
||||
/// The `+` binary SQL operator.
|
||||
/// The arithmetic `+` binary SQL operator.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -245,13 +266,19 @@ public struct SQLExpression {
|
||||
/// // score + bonus
|
||||
/// [Column("score"), Column("bonus")].joined(operator: .add)
|
||||
/// ```
|
||||
///
|
||||
/// The neutral value of the `add` operator, used when joining an
|
||||
/// empty sequence, is `0`.
|
||||
///
|
||||
/// The `add` operator performs a numeric addition. To concatenate
|
||||
/// strings, use the ``concat`` operator instead.
|
||||
public static let add = AssociativeBinaryOperator(
|
||||
sql: "+",
|
||||
neutralValue: 0.databaseValue,
|
||||
strictlyAssociative: false,
|
||||
bijective: false)
|
||||
|
||||
/// The `*` binary SQL operator.
|
||||
/// The arithmetic `*` binary SQL operator.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -259,13 +286,16 @@ public struct SQLExpression {
|
||||
/// // score * factor
|
||||
/// [Column("score"), Column("factor")].joined(operator: .multiply)
|
||||
/// ```
|
||||
///
|
||||
/// The neutral value of the `multiply` operator, used when joining an
|
||||
/// empty sequence, is `1`.
|
||||
public static let multiply = AssociativeBinaryOperator(
|
||||
sql: "*",
|
||||
neutralValue: 1.databaseValue,
|
||||
strictlyAssociative: false,
|
||||
bijective: false)
|
||||
|
||||
/// The `AND` binary SQL operator.
|
||||
/// The logical `AND` binary SQL operator.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -273,13 +303,16 @@ public struct SQLExpression {
|
||||
/// // isBlue AND isTall
|
||||
/// [Column("isBlue"), Column("isTall")].joined(operator: .and)
|
||||
/// ```
|
||||
///
|
||||
/// The neutral value of the `and` operator, used when joining an
|
||||
/// empty sequence, is `true`.
|
||||
public static let and = AssociativeBinaryOperator(
|
||||
sql: "AND",
|
||||
neutralValue: true.databaseValue,
|
||||
strictlyAssociative: true,
|
||||
bijective: false)
|
||||
|
||||
/// The `OR` binary SQL operator.
|
||||
/// The logical `OR` binary SQL operator.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -287,6 +320,9 @@ public struct SQLExpression {
|
||||
/// // isBlue OR isTall
|
||||
/// [Column("isBlue"), Column("isTall")].joined(operator: .or)
|
||||
/// ```
|
||||
///
|
||||
/// The neutral value of the `or` operator, used when joining an
|
||||
/// empty sequence, is `false`.
|
||||
public static let or = AssociativeBinaryOperator(
|
||||
sql: "OR",
|
||||
neutralValue: false.databaseValue,
|
||||
@@ -301,13 +337,16 @@ public struct SQLExpression {
|
||||
/// // firstName || ' ' || lastName
|
||||
/// [Column("firstName"), " ", Column("lastName")].joined(operator: .concat)
|
||||
/// ```
|
||||
///
|
||||
/// The neutral value of the `concat` operator, used when joining an
|
||||
/// empty sequence, is the empty string.
|
||||
public static let concat = AssociativeBinaryOperator(
|
||||
sql: "||",
|
||||
neutralValue: "".databaseValue,
|
||||
strictlyAssociative: true,
|
||||
bijective: true)
|
||||
|
||||
/// The `&` bitwise AND SQL operator.
|
||||
/// The bitwise `&` SQL operator.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -315,13 +354,17 @@ public struct SQLExpression {
|
||||
/// // mask & 2
|
||||
/// [Column("mask"), 2.databaseValue].joined(operator: .bitwiseAnd)
|
||||
/// ```
|
||||
///
|
||||
/// The neutral value of the `bitwiseAnd` operator, used when
|
||||
/// joining an empty sequence, is `-1` (the signed 64-bit integer
|
||||
/// with all bits set).
|
||||
public static let bitwiseAnd = AssociativeBinaryOperator(
|
||||
sql: "&",
|
||||
neutralValue: (-1).databaseValue,
|
||||
strictlyAssociative: true,
|
||||
bijective: false)
|
||||
|
||||
/// The `|` bitwise OR SQL operator.
|
||||
/// The bitwise `|` SQL operator.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
@@ -329,6 +372,9 @@ public struct SQLExpression {
|
||||
/// // mask | 2
|
||||
/// [Column("mask"), 2.databaseValue].joined(operator: .bitwiseOr)
|
||||
/// ```
|
||||
///
|
||||
/// The neutral value of the `bitwiseOr` operator, used when
|
||||
/// joining an empty sequence, is `0`.
|
||||
public static let bitwiseOr = AssociativeBinaryOperator(
|
||||
sql: "|",
|
||||
neutralValue: 0.databaseValue,
|
||||
@@ -1786,6 +1832,20 @@ extension SQLExpressible where Self == Column {
|
||||
/// - ``uppercased``
|
||||
/// - ``SQLDateModifier``
|
||||
///
|
||||
/// ### Create SQL Expressions from Sequences
|
||||
///
|
||||
/// - ``Swift/Sequence/contains(_:)-9i0ld``
|
||||
/// - ``Swift/Sequence/contains(_:)-o8ic``
|
||||
/// - ``Swift/Sequence/joined(operator:)-33dy5``
|
||||
/// - ``Swift/Sequence/joined(operator:)-4k88t``
|
||||
///
|
||||
/// ### Create SQL Expressions from Ranges
|
||||
///
|
||||
/// - ``Swift/ClosedRange/contains(_:)-64zwp``
|
||||
/// - ``Swift/ClosedRange/contains(_:)-19a6d``
|
||||
/// - ``Swift/Range/contains(_:)-11nr0``
|
||||
/// - ``Swift/Range/contains(_:)-3v32b``
|
||||
///
|
||||
/// ### Creating Ordering Terms
|
||||
///
|
||||
/// - ``asc``
|
||||
@@ -1853,13 +1913,8 @@ extension Sequence where Element: SQLSpecificExpressible {
|
||||
/// ```
|
||||
///
|
||||
/// When the sequence is empty, `joined(operator:)` returns the neutral
|
||||
/// value of the operator. It is:
|
||||
///
|
||||
/// - `0` for ``SQLExpression/AssociativeBinaryOperator/add``
|
||||
/// - `1` for ``SQLExpression/AssociativeBinaryOperator/multiply``
|
||||
/// - `false` for ``SQLExpression/AssociativeBinaryOperator/or``
|
||||
/// - `true` for ``SQLExpression/AssociativeBinaryOperator/and``
|
||||
/// - `""` for ``SQLExpression/AssociativeBinaryOperator/concat``
|
||||
/// value of the operator. See
|
||||
/// ``SQLExpression/AssociativeBinaryOperator`` for more information.
|
||||
public func joined(operator: SQLExpression.AssociativeBinaryOperator) -> SQLExpression {
|
||||
.associativeBinary(`operator`, map(\.sqlExpression))
|
||||
}
|
||||
@@ -1871,7 +1926,7 @@ extension Sequence where Element == any SQLSpecificExpressible {
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```
|
||||
/// ```swift
|
||||
/// // SELECT * FROM player
|
||||
/// // WHERE (registered
|
||||
/// // AND (score >= 1000)
|
||||
@@ -1884,13 +1939,8 @@ extension Sequence where Element == any SQLSpecificExpressible {
|
||||
/// ```
|
||||
///
|
||||
/// When the sequence is empty, `joined(operator:)` returns the neutral
|
||||
/// value of the operator. It is:
|
||||
///
|
||||
/// - `0` for ``SQLExpression/AssociativeBinaryOperator/add``
|
||||
/// - `1` for ``SQLExpression/AssociativeBinaryOperator/multiply``
|
||||
/// - `false` for ``SQLExpression/AssociativeBinaryOperator/or``
|
||||
/// - `true` for ``SQLExpression/AssociativeBinaryOperator/and``
|
||||
/// - `""` for ``SQLExpression/AssociativeBinaryOperator/concat``
|
||||
/// value of the operator. See
|
||||
/// ``SQLExpression/AssociativeBinaryOperator`` for more information.
|
||||
public func joined(operator: SQLExpression.AssociativeBinaryOperator) -> SQLExpression {
|
||||
.associativeBinary(`operator`, map(\.sqlExpression))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user