mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Cleanup Jazzy documentation from most redundant definitions and experimental APIs
This commit is contained in:
1 parent
dfcb44016f
commit
2289ed9d95
35 files changed
+283
-44
No files matched your search
@@ -87,6 +87,7 @@ public class AnyCursor<Element> : Cursor {
|
||||
|
||||
/// Advances to the next element and returns it, or nil if no next
|
||||
/// element exists.
|
||||
/// :nodoc:
|
||||
public func next() throws -> Element? {
|
||||
return try element()
|
||||
}
|
||||
@@ -231,6 +232,7 @@ public final class EnumeratedCursor<Base: Cursor> : Cursor {
|
||||
|
||||
/// Advances to the next element and returns it, or nil if no next
|
||||
/// element exists.
|
||||
/// :nodoc:
|
||||
public func next() throws -> (Int, Base.Element)? {
|
||||
guard let element = try base.next() else { return nil }
|
||||
defer { index += 1 }
|
||||
@@ -251,6 +253,7 @@ public final class FilterCursor<Base: Cursor> : Cursor {
|
||||
|
||||
/// Advances to the next element and returns it, or nil if no next
|
||||
/// element exists.
|
||||
/// :nodoc:
|
||||
public func next() throws -> Base.Element? {
|
||||
while let element = try base.next() {
|
||||
if try isIncluded(element) {
|
||||
@@ -275,6 +278,7 @@ public final class FlattenCursor<Base: Cursor> : Cursor where Base.Element: Curs
|
||||
|
||||
/// Advances to the next element and returns it, or nil if no next
|
||||
/// element exists.
|
||||
/// :nodoc:
|
||||
public func next() throws -> Base.Element.Element? {
|
||||
while true {
|
||||
if let element = try inner?.next() {
|
||||
@@ -303,6 +307,7 @@ public final class MapCursor<Base: Cursor, Element> : Cursor {
|
||||
|
||||
/// Advances to the next element and returns it, or nil if no next
|
||||
/// element exists.
|
||||
/// :nodoc:
|
||||
public func next() throws -> Element? {
|
||||
guard let element = try base.next() else { return nil }
|
||||
return try transform(element)
|
||||
@@ -327,6 +332,7 @@ public final class IteratorCursor<Base: IteratorProtocol> : Cursor {
|
||||
|
||||
/// Advances to the next element and returns it, or nil if no next
|
||||
/// element exists.
|
||||
/// :nodoc:
|
||||
public func next() -> Base.Element? {
|
||||
return base.next()
|
||||
}
|
||||
|
||||
@@ -817,8 +817,10 @@ extension Database {
|
||||
///
|
||||
/// See https://www.sqlite.org/datatype3.html#collation
|
||||
public struct CollationName : RawRepresentable, Hashable {
|
||||
/// :nodoc:
|
||||
public let rawValue: String
|
||||
|
||||
/// :nodoc:
|
||||
public init(rawValue: String) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
@@ -828,6 +830,7 @@ extension Database {
|
||||
}
|
||||
|
||||
/// The hash value
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
return rawValue.hashValue
|
||||
}
|
||||
@@ -851,8 +854,10 @@ extension Database {
|
||||
///
|
||||
/// See https://www.sqlite.org/datatype3.html
|
||||
public struct ColumnType : RawRepresentable, Hashable {
|
||||
/// :nodoc:
|
||||
public let rawValue: String
|
||||
|
||||
/// :nodoc:
|
||||
public init(rawValue: String) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
@@ -862,6 +867,7 @@ extension Database {
|
||||
}
|
||||
|
||||
/// The hash value
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
return rawValue.hashValue
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public final class DatabaseCollation {
|
||||
}
|
||||
|
||||
extension DatabaseCollation : Hashable {
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
// Collation equality is based on the sqlite3_strnicmp SQLite function.
|
||||
// (see https://www.sqlite.org/c3ref/create_collation.html). Computing
|
||||
@@ -44,6 +45,7 @@ extension DatabaseCollation : Hashable {
|
||||
}
|
||||
|
||||
/// Two collations are equal if they share the same name (case insensitive)
|
||||
/// :nodoc:
|
||||
public static func == (lhs: DatabaseCollation, rhs: DatabaseCollation) -> Bool {
|
||||
// See https://www.sqlite.org/c3ref/create_collation.html
|
||||
return sqlite3_stricmp(lhs.name, lhs.name) == 0
|
||||
|
||||
@@ -5,7 +5,7 @@ import Foundation
|
||||
import SQLite3
|
||||
#endif
|
||||
|
||||
public struct ResultCode : RawRepresentable {
|
||||
public struct ResultCode : RawRepresentable, Equatable, CustomStringConvertible {
|
||||
public let rawValue: Int32
|
||||
|
||||
public init(rawValue: Int32) {
|
||||
@@ -139,13 +139,17 @@ public struct ResultCode : RawRepresentable {
|
||||
public static let SQLITE_OK_LOAD_PERMANENTLY = ResultCode(rawValue: (SQLITE_OK.rawValue | (1<<8)))
|
||||
}
|
||||
|
||||
extension ResultCode : Equatable {
|
||||
// Equatable
|
||||
extension ResultCode {
|
||||
/// :nodoc:
|
||||
public static func == (_ lhs: ResultCode, _ rhs: ResultCode) -> Bool {
|
||||
return lhs.rawValue == rhs.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
extension ResultCode : CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension ResultCode {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
// sqlite3_errstr was added in SQLite 3.7.15 http://www.sqlite.org/changes.html#version_3_7_15
|
||||
// It is available from iOS 8.2 and OS X 10.10 https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)
|
||||
@@ -162,7 +166,7 @@ extension ResultCode : CustomStringConvertible {
|
||||
}
|
||||
|
||||
/// DatabaseError wraps an SQLite error.
|
||||
public struct DatabaseError : Error {
|
||||
public struct DatabaseError : Error, CustomStringConvertible, CustomNSError {
|
||||
|
||||
/// The SQLite error code (see
|
||||
/// https://www.sqlite.org/rescode.html#primary_result_code_list).
|
||||
@@ -223,7 +227,9 @@ public struct DatabaseError : Error {
|
||||
let arguments: StatementArguments?
|
||||
}
|
||||
|
||||
extension DatabaseError: CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension DatabaseError {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
var description = "SQLite error \(resultCode.rawValue)"
|
||||
if let sql = sql {
|
||||
@@ -239,19 +245,23 @@ extension DatabaseError: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseError : CustomNSError {
|
||||
// CustomNSError
|
||||
extension DatabaseError {
|
||||
|
||||
/// NSError bridging: the domain of the error.
|
||||
/// :nodoc:
|
||||
public static var errorDomain: String {
|
||||
return "GRDB.DatabaseError"
|
||||
}
|
||||
|
||||
/// NSError bridging: the error code within the given domain.
|
||||
/// :nodoc:
|
||||
public var errorCode: Int {
|
||||
return Int(extendedResultCode.rawValue)
|
||||
}
|
||||
|
||||
/// NSError bridging: the user-info dictionary.
|
||||
/// :nodoc:
|
||||
public var errorUserInfo: [String : Any] {
|
||||
return [NSLocalizedDescriptionKey: description]
|
||||
}
|
||||
|
||||
@@ -311,11 +311,13 @@ public final class DatabaseFunction {
|
||||
|
||||
extension DatabaseFunction : Hashable {
|
||||
/// The hash value
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
return name.hashValue ^ nArg.hashValue
|
||||
}
|
||||
|
||||
/// Two functions are equal if they share the same name and arity.
|
||||
/// :nodoc:
|
||||
public static func == (lhs: DatabaseFunction, rhs: DatabaseFunction) -> Bool {
|
||||
return lhs.name == rhs.name && lhs.nArg == rhs.nArg
|
||||
}
|
||||
|
||||
@@ -188,8 +188,8 @@ extension DatabaseQueue {
|
||||
|
||||
extension DatabaseQueue : DatabaseReader {
|
||||
|
||||
// MARK: - DatabaseReader Protocol Adoption
|
||||
|
||||
// MARK: - Reading from Database
|
||||
|
||||
/// Synchronously executes a read-only block in a protected dispatch queue,
|
||||
/// and returns its result.
|
||||
///
|
||||
@@ -220,6 +220,8 @@ extension DatabaseQueue : DatabaseReader {
|
||||
}
|
||||
|
||||
/// Alias for `inDatabase`. See `DatabaseReader.unsafeRead`.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try inDatabase(block)
|
||||
}
|
||||
@@ -233,6 +235,8 @@ extension DatabaseQueue : DatabaseReader {
|
||||
///
|
||||
/// This method is reentrant. It should be avoided because it fosters
|
||||
/// dangerous concurrency practices.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try serializedDatabase.reentrantSync(block)
|
||||
}
|
||||
@@ -282,10 +286,10 @@ extension DatabaseQueue : DatabaseReader {
|
||||
}
|
||||
|
||||
extension DatabaseQueue : DatabaseWriter {
|
||||
|
||||
// MARK: - DatabaseWriter Protocol Adoption
|
||||
|
||||
/// Alias for `inDatabase`. See `DatabaseWriter.write`.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func write<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try inDatabase(block)
|
||||
}
|
||||
@@ -300,6 +304,8 @@ extension DatabaseQueue : DatabaseWriter {
|
||||
/// outside of a transaction. You'll get a fatal error otherwise.
|
||||
///
|
||||
/// See `DatabaseWriter.readFromCurrentState`.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func readFromCurrentState(_ block: @escaping (Database) -> Void) {
|
||||
// Check that we're on the correct queue...
|
||||
serializedDatabase.execute { db in
|
||||
@@ -320,6 +326,8 @@ extension DatabaseQueue : DatabaseWriter {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Unsafe Database Access
|
||||
|
||||
/// Synchronously executes a block in a protected dispatch queue, and
|
||||
/// returns its result.
|
||||
///
|
||||
|
||||
@@ -223,34 +223,41 @@ public final class AnyDatabaseReader : DatabaseReader {
|
||||
|
||||
// MARK: - Reading from Database
|
||||
|
||||
/// :nodoc:
|
||||
public func read<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.read(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeRead(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeReentrantRead(block)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
/// :nodoc:
|
||||
public func add(function: DatabaseFunction) {
|
||||
base.add(function: function)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func remove(function: DatabaseFunction) {
|
||||
base.remove(function: function)
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
/// :nodoc:
|
||||
public func add(collation: DatabaseCollation) {
|
||||
base.add(collation: collation)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func remove(collation: DatabaseCollation) {
|
||||
base.remove(collation: collation)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
/// // A query interface request that executes the same statement:
|
||||
/// let request = Player.filter(key: 1)
|
||||
/// try request.fetchedRegion(db) // "players(*)[1]"
|
||||
public struct DatabaseRegion {
|
||||
public struct DatabaseRegion: CustomStringConvertible, Equatable {
|
||||
private let tableRegions: [String: TableRegion]?
|
||||
private init(tableRegions: [String: TableRegion]?) {
|
||||
self.tableRegions = tableRegions
|
||||
@@ -192,7 +192,9 @@ extension DatabaseRegion {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseRegion: Equatable {
|
||||
// Equatable
|
||||
extension DatabaseRegion {
|
||||
/// :nodoc:
|
||||
public static func == (lhs: DatabaseRegion, rhs: DatabaseRegion) -> Bool {
|
||||
switch (lhs.tableRegions, rhs.tableRegions) {
|
||||
case (nil, nil):
|
||||
@@ -215,7 +217,9 @@ extension DatabaseRegion: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseRegion: CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension DatabaseRegion {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
guard let tableRegions = tableRegions else {
|
||||
return "full database"
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
/// DatabaseValue is the intermediate type between SQLite and your values.
|
||||
///
|
||||
/// See https://www.sqlite.org/datatype3.html
|
||||
public struct DatabaseValue {
|
||||
public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueConvertible, SQLExpressible, SQLExpression {
|
||||
/// The SQLite storage
|
||||
public let storage: Storage
|
||||
|
||||
@@ -146,9 +146,11 @@ public struct DatabaseValue {
|
||||
|
||||
// MARK: - Hashable & Equatable
|
||||
|
||||
extension DatabaseValue : Hashable {
|
||||
// Hashable
|
||||
extension DatabaseValue {
|
||||
|
||||
/// The hash value
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
switch storage {
|
||||
case .null:
|
||||
@@ -280,7 +282,8 @@ extension DatabaseValue {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValue : DatabaseValueConvertible {
|
||||
// DatabaseValueConvertible
|
||||
extension DatabaseValue {
|
||||
/// Returns self
|
||||
public var databaseValue: DatabaseValue {
|
||||
return self
|
||||
@@ -292,15 +295,19 @@ extension DatabaseValue : DatabaseValueConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValue : SQLExpressible {
|
||||
// SQLExpressible
|
||||
extension DatabaseValue {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var sqlExpression: SQLExpression {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValue : SQLExpression {
|
||||
// SQLExpression
|
||||
extension DatabaseValue {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
// fast path for NULL
|
||||
if isNull {
|
||||
@@ -318,6 +325,7 @@ extension DatabaseValue : SQLExpression {
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var negated: SQLExpression {
|
||||
switch storage {
|
||||
case .null:
|
||||
@@ -343,7 +351,9 @@ extension DatabaseValue : SQLExpression {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValue : CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension DatabaseValue {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
switch storage {
|
||||
case .null:
|
||||
|
||||
@@ -32,6 +32,7 @@ public protocol DatabaseValueConvertible : SQLExpressible {
|
||||
|
||||
extension DatabaseValueConvertible {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var sqlExpression: SQLExpression {
|
||||
return databaseValue
|
||||
}
|
||||
@@ -60,6 +61,7 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible> : Cursor
|
||||
statement.cursorReset(arguments: arguments)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func next() throws -> Value? {
|
||||
if done { return nil }
|
||||
switch sqlite3_step(sqliteStatement) {
|
||||
@@ -99,6 +101,7 @@ public final class NullableDatabaseValueCursor<Value: DatabaseValueConvertible>
|
||||
statement.cursorReset(arguments: arguments)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func next() throws -> Value?? {
|
||||
if done { return nil }
|
||||
switch sqlite3_step(sqliteStatement) {
|
||||
|
||||
@@ -96,48 +96,58 @@ public final class AnyDatabaseWriter : DatabaseWriter {
|
||||
|
||||
// MARK: - Reading from Database
|
||||
|
||||
/// :nodoc:
|
||||
public func read<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.read(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeRead(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeReentrantRead(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func readFromCurrentState(_ block: @escaping (Database) -> Void) throws {
|
||||
try base.readFromCurrentState(block)
|
||||
}
|
||||
|
||||
// MARK: - Writing in Database
|
||||
|
||||
/// :nodoc:
|
||||
public func write<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try base.write(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantWrite<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try base.unsafeReentrantWrite(block)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
/// :nodoc:
|
||||
public func add(function: DatabaseFunction) {
|
||||
base.add(function: function)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func remove(function: DatabaseFunction) {
|
||||
base.remove(function: function)
|
||||
}
|
||||
|
||||
// MARK: - Collations
|
||||
|
||||
/// :nodoc:
|
||||
public func add(collation: DatabaseCollation) {
|
||||
base.add(collation: collation)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func remove(collation: DatabaseCollation) {
|
||||
base.remove(collation: collation)
|
||||
}
|
||||
|
||||
+15
-1
@@ -103,6 +103,7 @@ public struct AdaptedRequest<Base: Request> : Request {
|
||||
self.adapter = adapter
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
let (statement, baseAdapter) = try base.prepare(db)
|
||||
if let baseAdapter = baseAdapter {
|
||||
@@ -112,10 +113,12 @@ public struct AdaptedRequest<Base: Request> : Request {
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
@@ -145,14 +148,17 @@ public struct AnyRequest : Request {
|
||||
base = PrepareRequest(base: prepare)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try base.prepare(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
@@ -205,7 +211,9 @@ public struct SQLRequest : Request {
|
||||
/// executed, and an eventual row adapter.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
///
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
let statement: SelectStatement
|
||||
switch cache {
|
||||
case .none:
|
||||
@@ -272,14 +280,17 @@ public struct AdaptedTypedRequest<Base: TypedRequest> : TypedRequest {
|
||||
self.base = AdaptedRequest(base, adapter)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try base.prepare(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
@@ -311,14 +322,17 @@ public struct AnyTypedRequest<T> : TypedRequest {
|
||||
base = AnyRequest(prepare)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try base.prepare(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.fetchedRegion(db)
|
||||
}
|
||||
|
||||
+28
-13
@@ -6,7 +6,7 @@ import Foundation
|
||||
#endif
|
||||
|
||||
/// A database row.
|
||||
public final class Row {
|
||||
public final class Row : Equatable, Hashable, RandomAccessCollection, ExpressibleByDictionaryLiteral, CustomStringConvertible {
|
||||
let impl: RowImpl
|
||||
|
||||
/// Unless we are producing a row array, we use a single row when iterating
|
||||
@@ -506,6 +506,7 @@ public final class RowCursor : Cursor {
|
||||
statement.cursorReset(arguments: arguments)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func next() throws -> Row? {
|
||||
if done { return nil }
|
||||
switch sqlite3_step(sqliteStatement) {
|
||||
@@ -725,7 +726,8 @@ extension Row {
|
||||
}
|
||||
}
|
||||
|
||||
extension Row : ExpressibleByDictionaryLiteral {
|
||||
// ExpressibleByDictionaryLiteral
|
||||
extension Row {
|
||||
|
||||
/// Creates a row initialized with elements. Column order is preserved, and
|
||||
/// duplicated columns names are allowed.
|
||||
@@ -738,17 +740,20 @@ extension Row : ExpressibleByDictionaryLiteral {
|
||||
}
|
||||
}
|
||||
|
||||
extension Row : RandomAccessCollection {
|
||||
// RandomAccessCollection
|
||||
extension Row {
|
||||
|
||||
// MARK: - Row as a Collection of (ColumnName, DatabaseValue) Pairs
|
||||
|
||||
/// The index of the first (ColumnName, DatabaseValue) pair.
|
||||
/// :nodoc:
|
||||
public var startIndex: RowIndex {
|
||||
return Index(0)
|
||||
}
|
||||
|
||||
/// The "past-the-end" index, successor of the index of the last
|
||||
/// (ColumnName, DatabaseValue) pair.
|
||||
/// :nodoc:
|
||||
public var endIndex: RowIndex {
|
||||
return Index(count)
|
||||
}
|
||||
@@ -763,11 +768,12 @@ extension Row : RandomAccessCollection {
|
||||
}
|
||||
}
|
||||
|
||||
/// Row adopts Equatable.
|
||||
extension Row : Equatable {
|
||||
// Equatable
|
||||
extension Row {
|
||||
|
||||
/// Returns true if and only if both rows have the same columns and values,
|
||||
/// in the same order. Columns are compared in a case-sensitive way.
|
||||
/// :nodoc:
|
||||
public static func == (lhs: Row, rhs: Row) -> Bool {
|
||||
if lhs === rhs {
|
||||
return true
|
||||
@@ -804,17 +810,19 @@ extension Row : Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
/// Row adopts Hashable.
|
||||
extension Row : Hashable {
|
||||
// Hashable
|
||||
extension Row {
|
||||
/// The hash value
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
return columnNames.reduce(0) { (acc, column) in acc ^ column.hashValue } ^
|
||||
databaseValues.reduce(0) { (acc, dbValue) in acc ^ dbValue.hashValue }
|
||||
}
|
||||
}
|
||||
|
||||
/// Row adopts CustomStringConvertible.
|
||||
extension Row: CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension Row {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
return "<Row"
|
||||
+ map { (column, dbValue) in
|
||||
@@ -828,25 +836,32 @@ extension Row: CustomStringConvertible {
|
||||
// MARK: - RowIndex
|
||||
|
||||
/// Indexes to (ColumnName, DatabaseValue) pairs in a database row.
|
||||
public struct RowIndex : Comparable {
|
||||
public struct RowIndex : Comparable, Strideable {
|
||||
let index: Int
|
||||
init(_ index: Int) { self.index = index }
|
||||
|
||||
}
|
||||
|
||||
// Comparable
|
||||
extension RowIndex {
|
||||
/// :nodoc:
|
||||
public static func == (lhs: RowIndex, rhs: RowIndex) -> Bool {
|
||||
return lhs.index == rhs.index
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public static func < (lhs: RowIndex, rhs: RowIndex) -> Bool {
|
||||
return lhs.index < rhs.index
|
||||
}
|
||||
}
|
||||
|
||||
// Support for Row: RandomAccessCollection
|
||||
extension RowIndex: Strideable {
|
||||
// Strideable: support for Row: RandomAccessCollection
|
||||
extension RowIndex {
|
||||
/// :nodoc:
|
||||
public func distance(to other: RowIndex) -> Int {
|
||||
return other.index - index
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func advanced(by n: Int) -> RowIndex {
|
||||
return RowIndex(index + n)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import Foundation
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// LayoutedColumnMapping is a type that supports the RowAdapter protocol.
|
||||
///
|
||||
/// :nodoc:
|
||||
public struct LayoutedColumnMapping {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -56,6 +58,8 @@ public struct LayoutedColumnMapping {
|
||||
}
|
||||
|
||||
/// LayoutedColumnMapping adopts LayoutedRowAdapter
|
||||
///
|
||||
/// :nodoc:
|
||||
extension LayoutedColumnMapping : LayoutedRowAdapter {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -72,6 +76,7 @@ extension LayoutedColumnMapping : LayoutedRowAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
extension LayoutedColumnMapping : RowLayout {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -91,6 +96,8 @@ extension LayoutedColumnMapping : RowLayout {
|
||||
///
|
||||
/// GRBD ships with a ready-made type that adopts this protocol:
|
||||
/// LayoutedColumnMapping.
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol LayoutedRowAdapter {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -108,6 +115,8 @@ public protocol LayoutedRowAdapter {
|
||||
///
|
||||
/// RowLayout is a protocol that supports the RowAdapter protocol. It describes
|
||||
/// a layout of a base row.
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol RowLayout {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -124,11 +133,15 @@ public protocol RowLayout {
|
||||
|
||||
extension SelectStatement : RowLayout {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public var layoutColumns: [(Int, String)] {
|
||||
return Array(columnNames.enumerated())
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func layoutIndex(ofColumn name: String) -> Int? {
|
||||
return index(ofColumn: name)
|
||||
}
|
||||
@@ -214,6 +227,8 @@ public struct ColumnMapping : RowAdapter {
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
let layoutColumns = try mapping
|
||||
.map { (mappedColumn, baseColumn) -> (Int, String) in
|
||||
@@ -250,6 +265,8 @@ public struct SuffixRowAdapter : RowAdapter {
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
return LayoutedColumnMapping(layoutColumns: layout.layoutColumns.suffix(from: index))
|
||||
}
|
||||
@@ -279,6 +296,8 @@ public struct RangeRowAdapter : RowAdapter {
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
return LayoutedColumnMapping(layoutColumns: layout.layoutColumns[range])
|
||||
}
|
||||
@@ -329,6 +348,8 @@ public struct ScopeAdapter : RowAdapter {
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
let layoutedAdapter = try mainAdapter.layoutedAdapter(from: layout)
|
||||
var layoutedScopes = layoutedAdapter.scopes
|
||||
|
||||
@@ -291,10 +291,12 @@ extension AuthorizedStatement {
|
||||
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
|
||||
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
|
||||
/// }
|
||||
public final class SelectStatement : Statement, AuthorizedStatement {
|
||||
public final class SelectStatement : Statement {
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed:"DatabaseRegion")
|
||||
public typealias SelectionInfo = DatabaseRegion
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, renamed:"fetchedRegion")
|
||||
public var selectionInfo: DatabaseRegion { return fetchedRegion }
|
||||
|
||||
@@ -372,6 +374,9 @@ public final class SelectStatement : Statement, AuthorizedStatement {
|
||||
}
|
||||
}
|
||||
|
||||
// Hide AuthorizedStatement from Jazzy
|
||||
extension SelectStatement: AuthorizedStatement { }
|
||||
|
||||
/// A cursor that iterates a database statement without producing any value.
|
||||
/// For example:
|
||||
///
|
||||
@@ -391,6 +396,7 @@ public final class StatementCursor: Cursor {
|
||||
statement.cursorReset(arguments: arguments)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func next() throws -> Void? {
|
||||
if done { return nil }
|
||||
switch sqlite3_step(sqliteStatement) {
|
||||
@@ -419,7 +425,7 @@ public final class StatementCursor: Cursor {
|
||||
/// try statement.execute(arguments: ["Barbara"])
|
||||
/// return .commit
|
||||
/// }
|
||||
public final class UpdateStatement : Statement, AuthorizedStatement {
|
||||
public final class UpdateStatement : Statement {
|
||||
enum TransactionEffect {
|
||||
case beginTransaction
|
||||
case commitTransaction
|
||||
@@ -510,6 +516,9 @@ public final class UpdateStatement : Statement, AuthorizedStatement {
|
||||
}
|
||||
}
|
||||
|
||||
// Hide AuthorizedStatement from Jazzy
|
||||
extension UpdateStatement: AuthorizedStatement { }
|
||||
|
||||
|
||||
// MARK: - StatementArguments
|
||||
|
||||
@@ -584,7 +593,7 @@ public final class UpdateStatement : Statement, AuthorizedStatement {
|
||||
/// let row = try Row.fetchOne(db, sql, arguments: [1, 2, "bar"] + ["foo": "foo"])!
|
||||
/// print(row)
|
||||
/// // Prints <Row two:2 foo:"foo" one:1 foo2:"foo" bar:"bar">
|
||||
public struct StatementArguments {
|
||||
public struct StatementArguments: CustomStringConvertible, Equatable, ExpressibleByArrayLiteral, ExpressibleByDictionaryLiteral {
|
||||
var values: [DatabaseValue] = []
|
||||
var namedValues: [String: DatabaseValue] = [:]
|
||||
|
||||
@@ -870,7 +879,8 @@ public struct StatementArguments {
|
||||
}
|
||||
}
|
||||
|
||||
extension StatementArguments : ExpressibleByArrayLiteral {
|
||||
// ExpressibleByArrayLiteral
|
||||
extension StatementArguments {
|
||||
/// Returns a StatementArguments from an array literal:
|
||||
///
|
||||
/// db.selectRows("SELECT ...", arguments: ["Arthur", 41])
|
||||
@@ -879,7 +889,8 @@ extension StatementArguments : ExpressibleByArrayLiteral {
|
||||
}
|
||||
}
|
||||
|
||||
extension StatementArguments : ExpressibleByDictionaryLiteral {
|
||||
// ExpressibleByDictionaryLiteral
|
||||
extension StatementArguments {
|
||||
/// Returns a StatementArguments from a dictionary literal:
|
||||
///
|
||||
/// db.selectRows("SELECT ...", arguments: ["name": "Arthur", "score": 41])
|
||||
@@ -888,7 +899,9 @@ extension StatementArguments : ExpressibleByDictionaryLiteral {
|
||||
}
|
||||
}
|
||||
|
||||
extension StatementArguments : CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension StatementArguments {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
let valuesDescriptions = values.map { $0.description }
|
||||
let namedValuesDescriptions = namedValues.map { (key, value) -> String in
|
||||
@@ -898,7 +911,9 @@ extension StatementArguments : CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension StatementArguments : Equatable {
|
||||
// Equatable
|
||||
extension StatementArguments {
|
||||
/// :nodoc:
|
||||
public static func == (lhs: StatementArguments, rhs: StatementArguments) -> Bool {
|
||||
if lhs.values != rhs.values { return false }
|
||||
if lhs.namedValues != rhs.namedValues { return false }
|
||||
|
||||
@@ -73,6 +73,7 @@ public final class ColumnCursor<Value: DatabaseValueConvertible & StatementColum
|
||||
statement.cursorReset(arguments: arguments)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func next() throws -> Value? {
|
||||
if done { return nil }
|
||||
switch sqlite3_step(sqliteStatement) {
|
||||
@@ -118,6 +119,7 @@ public final class NullableColumnCursor<Value: DatabaseValueConvertible & Statem
|
||||
statement.cursorReset(arguments: arguments)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func next() throws -> Value?? {
|
||||
if done { return nil }
|
||||
switch sqlite3_step(sqliteStatement) {
|
||||
|
||||
@@ -875,6 +875,7 @@ public enum DatabaseEventKind {
|
||||
}
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@available(*, deprecated, message: "Use DatabaseRegion.isModified(byEventsOfKind:) instead")
|
||||
public func impacts(_ region: DatabaseRegion) -> Bool {
|
||||
return region.isModified(byEventsOfKind: self)
|
||||
|
||||
@@ -269,6 +269,7 @@ public final class FTS4ColumnDefinition {
|
||||
/// See https://www.sqlite.org/fts3.html#the_notindexed_option
|
||||
///
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
/// :nodoc:
|
||||
@discardableResult
|
||||
public func notIndexed() -> Self {
|
||||
// notindexed FTS4 option was added in SQLite 3.8.0 http://www.sqlite.org/changes.html#version_3_8_0
|
||||
|
||||
@@ -85,6 +85,8 @@ public struct DatabaseMigrator {
|
||||
/// - identifier: The migration identifier.
|
||||
/// - block: The migration block that performs SQL statements.
|
||||
/// - precondition: No migration with the same same as already been registered.
|
||||
///
|
||||
/// :nodoc:
|
||||
public mutating func registerMigrationWithDeferredForeignKeyCheck(_ identifier: String, migrate: @escaping (Database) throws -> Void) {
|
||||
registerMigration(Migration(identifier: identifier, disabledForeignKeyChecks: true, migrate: migrate))
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ public struct Column {
|
||||
extension Column : SQLExpression {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
return name.quotedDatabaseIdentifier
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ extension QueryInterfaceRequest : TypedRequest {
|
||||
/// executed, and an eventual row adapter.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try query.prepare(db)
|
||||
}
|
||||
@@ -23,11 +25,15 @@ extension QueryInterfaceRequest : TypedRequest {
|
||||
/// The number of rows fetched by the request.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try query.fetchCount(db)
|
||||
}
|
||||
|
||||
/// The database region that the request looks into.
|
||||
///
|
||||
/// :nodoc:
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try query.fetchedRegion(db)
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ extension QueryInterfaceSelectQueryDefinition : Request {
|
||||
}
|
||||
|
||||
/// The database region that the request looks into.
|
||||
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
let (statement, _) = try prepare(db)
|
||||
let region = statement.fetchedRegion
|
||||
|
||||
|
||||
@@ -51,11 +51,15 @@ public struct SQLCollatedExpression {
|
||||
extension SQLCollatedExpression : SQLOrderingTerm {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public var reversed: SQLOrderingTerm {
|
||||
return desc
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func orderingTermSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
return sqlExpression.orderingTermSQL(&arguments)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// SQLCollection is the protocol for types that can be checked for inclusion.
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol SQLCollection {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
/// like Column.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol SQLExpressible {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -27,6 +29,8 @@ public protocol SQLExpressible {
|
||||
/// and it adopts SQLSpecificExpressible.
|
||||
///
|
||||
/// On the other side, Int adopts SQLExpressible (via DatabaseValueConvertible).
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol SQLSpecificExpressible : SQLExpressible {
|
||||
// SQLExpressible can be adopted by Swift standard types, and user
|
||||
// types, through the DatabaseValueConvertible protocol which inherits
|
||||
@@ -53,11 +57,15 @@ public protocol SQLSpecificExpressible : SQLExpressible {
|
||||
extension SQLExpressible where Self: SQLOrderingTerm {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public var reversed: SQLOrderingTerm {
|
||||
return SQLOrdering.desc(sqlExpression)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func orderingTermSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
return sqlExpression.expressionSQL(&arguments)
|
||||
}
|
||||
@@ -68,16 +76,22 @@ extension SQLExpressible where Self: SQLOrderingTerm {
|
||||
extension SQLExpressible where Self: SQLSelectable {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func resultColumnSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
return sqlExpression.expressionSQL(&arguments)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func countedSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
return sqlExpression.expressionSQL(&arguments)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func count(distinct: Bool) -> SQLCount? {
|
||||
return sqlExpression.count(distinct: distinct)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ extension SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// Converts an expression to an SQLExpressionLiteral
|
||||
///
|
||||
/// :nodoc:
|
||||
public var literal: SQLExpressionLiteral {
|
||||
var arguments: StatementArguments? = []
|
||||
let sql = expressionSQL(&arguments)
|
||||
@@ -57,6 +59,8 @@ public struct SQLExpressionLiteral : SQLExpression {
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
if let literalArguments = self.arguments {
|
||||
guard arguments != nil else {
|
||||
@@ -75,6 +79,8 @@ public struct SQLExpressionLiteral : SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// SQLUnaryOperator is a SQLite unary operator.
|
||||
///
|
||||
/// :nodoc:
|
||||
public struct SQLUnaryOperator : Hashable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -97,11 +103,15 @@ public struct SQLUnaryOperator : Hashable {
|
||||
}
|
||||
|
||||
/// The hash value
|
||||
///
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
return sql.hashValue
|
||||
}
|
||||
|
||||
/// Equality operator
|
||||
///
|
||||
/// :nodoc:
|
||||
public static func == (lhs: SQLUnaryOperator, rhs: SQLUnaryOperator) -> Bool {
|
||||
return lhs.sql == rhs.sql
|
||||
}
|
||||
@@ -113,6 +123,8 @@ public struct SQLUnaryOperator : Hashable {
|
||||
/// an operand expression.
|
||||
///
|
||||
/// SQLExpressionUnary(.not, Column("favorite"))
|
||||
///
|
||||
/// :nodoc:
|
||||
public struct SQLExpressionUnary : SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -147,6 +159,8 @@ public struct SQLExpressionUnary : SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// SQLBinaryOperator is a SQLite binary operator.
|
||||
///
|
||||
/// :nodoc:
|
||||
public struct SQLBinaryOperator : Hashable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -223,6 +237,8 @@ public struct SQLBinaryOperator : Hashable {
|
||||
/// binary operator.
|
||||
///
|
||||
/// SQLExpressionBinary(.multiply, Column("length"), Column("width"))
|
||||
///
|
||||
/// :nodoc:
|
||||
public struct SQLExpressionBinary : SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
@@ -420,6 +436,8 @@ public struct SQLFunctionName : Hashable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// The SQL function name
|
||||
///
|
||||
/// :nodoc:
|
||||
public let sql: String
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -427,16 +445,22 @@ public struct SQLFunctionName : Hashable {
|
||||
/// Creates a function name
|
||||
///
|
||||
/// SQLFunctionName("ABS")
|
||||
///
|
||||
/// :nodoc:
|
||||
public init(_ sql: String) {
|
||||
self.sql = sql
|
||||
}
|
||||
|
||||
/// The hash value
|
||||
///
|
||||
/// :nodoc:
|
||||
public var hashValue: Int {
|
||||
return sql.hashValue
|
||||
}
|
||||
|
||||
/// Equality operator
|
||||
///
|
||||
/// :nodoc:
|
||||
public static func == (lhs: SQLFunctionName, rhs: SQLFunctionName) -> Bool {
|
||||
return lhs.sql == rhs.sql
|
||||
}
|
||||
@@ -448,6 +472,8 @@ public struct SQLFunctionName : Hashable {
|
||||
///
|
||||
/// // ABS(-1)
|
||||
/// SQLExpressionFunction(.abs, [-1.databaseValue])
|
||||
///
|
||||
/// :nodoc:
|
||||
public struct SQLExpressionFunction : SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
/// - SQLExpressionExists
|
||||
/// - SQLExpressionFunction
|
||||
/// - SQLExpressionCollate
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol SQLExpression : SQLSpecificExpressible, SQLSelectable, SQLOrderingTerm {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -69,6 +71,7 @@ extension SQLExpression {
|
||||
/// let column = Column("favorite")
|
||||
/// column.negated // NOT favorite
|
||||
///
|
||||
/// :nodoc:
|
||||
public var negated: SQLExpression {
|
||||
return SQLExpressionNot(self)
|
||||
}
|
||||
@@ -76,6 +79,8 @@ extension SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// The default implementation returns nil
|
||||
///
|
||||
/// :nodoc:
|
||||
public func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
|
||||
return nil
|
||||
}
|
||||
@@ -86,6 +91,8 @@ extension SQLExpression {
|
||||
extension SQLExpression {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public var sqlExpression: SQLExpression {
|
||||
return self
|
||||
}
|
||||
@@ -96,6 +103,8 @@ extension SQLExpression {
|
||||
extension SQLExpression {
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func count(distinct: Bool) -> SQLCount? {
|
||||
if distinct {
|
||||
// SELECT DISTINCT expr FROM tableName ...
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
///
|
||||
/// The protocol for all types that can be used as an SQL ordering term, as
|
||||
/// described at https://www.sqlite.org/syntax/ordering-term.html
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol SQLOrderingTerm {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
|
||||
@@ -21,16 +21,22 @@ public struct AllColumns {
|
||||
|
||||
extension AllColumns : SQLSelectable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func resultColumnSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
return "*"
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func countedSQL(_ arguments: inout StatementArguments?) -> String {
|
||||
return "*"
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public func count(distinct: Bool) -> SQLCount? {
|
||||
// SELECT DISTINCT * FROM tableName ...
|
||||
guard !distinct else {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
///
|
||||
/// SQLSelectable is the protocol for types that can be selected, as
|
||||
/// described at https://www.sqlite.org/syntax/result-column.html
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol SQLSelectable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
func resultColumnSQL(_ arguments: inout StatementArguments?) -> String
|
||||
@@ -18,6 +20,8 @@ public protocol SQLSelectable {
|
||||
// MARK: - Counting
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public enum SQLCount {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
|
||||
@@ -587,7 +587,7 @@ extension SQLBinaryOperator {
|
||||
|
||||
extension SQLUnaryOperator {
|
||||
/// The `-` unary operator
|
||||
public static let minus = SQLUnaryOperator("-", needsRightSpace: false)
|
||||
static let minus = SQLUnaryOperator("-", needsRightSpace: false)
|
||||
}
|
||||
|
||||
/// An SQL arithmetic multiplication.
|
||||
|
||||
@@ -13,14 +13,16 @@ extension Database.ConflictResolution {
|
||||
// MARK: - PersistenceError
|
||||
|
||||
/// An error thrown by a type that adopts Persistable.
|
||||
public enum PersistenceError: Error {
|
||||
public enum PersistenceError: Error, CustomStringConvertible {
|
||||
|
||||
/// Thrown by MutablePersistable.update() when no matching row could be
|
||||
/// found in the database.
|
||||
case recordNotFound(MutablePersistable)
|
||||
}
|
||||
|
||||
extension PersistenceError : CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension PersistenceError {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .recordNotFound(let persistable):
|
||||
@@ -96,6 +98,8 @@ public struct PersistenceContainer {
|
||||
|
||||
/// Accesses the value associated with the given column, in a
|
||||
/// case-insensitive fashion.
|
||||
///
|
||||
/// :nodoc:
|
||||
subscript(caseInsensitive column: String) -> DatabaseValueConvertible? {
|
||||
get {
|
||||
if let value = storage[column] {
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
/// playerRecord.persistentChangedValues["score"] // 100 (the old value)
|
||||
/// }
|
||||
public final class RecordBox<T: RowConvertible & MutablePersistable>: Record {
|
||||
/// The boxed record
|
||||
public var value: T
|
||||
|
||||
/// Creates a RecordBox that wraps the given record
|
||||
public init(value: T) {
|
||||
self.value = value
|
||||
super.init()
|
||||
@@ -31,6 +33,7 @@ public final class RecordBox<T: RowConvertible & MutablePersistable>: Record {
|
||||
|
||||
// MARK: - RowConvertible
|
||||
|
||||
/// Initializes a record from `row`.
|
||||
public required init(row: Row) {
|
||||
self.value = T(row: row)
|
||||
super.init(row: row)
|
||||
@@ -38,38 +41,46 @@ public final class RecordBox<T: RowConvertible & MutablePersistable>: Record {
|
||||
|
||||
// MARK: - TableMapping
|
||||
|
||||
/// :nodoc:
|
||||
override public class var databaseTableName: String {
|
||||
return T.databaseTableName
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
override public class var databaseSelection: [SQLSelectable] {
|
||||
return T.databaseSelection
|
||||
}
|
||||
|
||||
// MARK: - MutablePersistable
|
||||
|
||||
/// :nodoc:
|
||||
override public class var persistenceConflictPolicy: PersistenceConflictPolicy {
|
||||
return T.persistenceConflictPolicy
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
override public func encode(to container: inout PersistenceContainer) {
|
||||
value.encode(to: &container)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
override public func didInsert(with rowID: Int64, for column: String?) {
|
||||
value.didInsert(with: rowID, for: column)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
override public func insert(_ db: Database) throws {
|
||||
try value.insert(db)
|
||||
hasPersistentChangedValues = false
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
override public func update(_ db: Database, columns: Set<String>) throws {
|
||||
try value.update(db, columns: columns)
|
||||
hasPersistentChangedValues = false
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@discardableResult
|
||||
override public func delete(_ db: Database) throws -> Bool {
|
||||
defer {
|
||||
@@ -81,6 +92,7 @@ public final class RecordBox<T: RowConvertible & MutablePersistable>: Record {
|
||||
return try value.delete(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func exists(_ db: Database) throws -> Bool {
|
||||
return try value.exists(db)
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public final class RecordCursor<Record: RowConvertible> : Cursor {
|
||||
statement.cursorReset(arguments: arguments)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func next() throws -> Record? {
|
||||
if done { return nil }
|
||||
switch sqlite3_step(sqliteStatement) {
|
||||
|
||||
@@ -23,16 +23,24 @@ public func databaseQuestionMarks(count: Int) -> String {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// This protocol is an implementation detail of GRDB. Don't use it.
|
||||
///
|
||||
/// :nodoc:
|
||||
public protocol _OptionalProtocol {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
associatedtype _Wrapped
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// This conformance is an implementation detail of GRDB. Don't rely on it.
|
||||
///
|
||||
/// :nodoc:
|
||||
extension Optional : _OptionalProtocol {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// :nodoc:
|
||||
public typealias _Wrapped = Wrapped
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user