diff --git a/Sources/SQLite/Row/SQLiteColumn.swift b/Sources/SQLite/Row/SQLiteColumn.swift index 09ef4d1..3508861 100644 --- a/Sources/SQLite/Row/SQLiteColumn.swift +++ b/Sources/SQLite/Row/SQLiteColumn.swift @@ -1,3 +1,4 @@ +/// Column in a SQLite result set. public struct SQLiteColumn { /// The table name. public var table: String? diff --git a/Sources/SQLite/Row/SQLiteData.swift b/Sources/SQLite/Row/SQLiteData.swift index 00bfd5a..c287d61 100644 --- a/Sources/SQLite/Row/SQLiteData.swift +++ b/Sources/SQLite/Row/SQLiteData.swift @@ -1,12 +1,30 @@ +/// Supported SQLite data types. public enum SQLiteData: Equatable, Encodable { + /// `Int`. case integer(Int) + + /// `Double`. case float(Double) + + /// `String`. case text(String) + + /// `Data`. case blob(Foundation.Data) + + /// `NULL`. case null + /// See `Encodable`. public func encode(to encoder: Encoder) throws { - fatalError() + var container = encoder.singleValueContainer() + switch self { + case .integer(let value): try container.encode(value) + case .float(let value): try container.encode(value) + case .text(let value): try container.encode(value) + case .blob(let value): try container.encode(value) + case .null: try container.encodeNil() + } } } diff --git a/Sources/SQLite/Row/SQLiteDataConvertible.swift b/Sources/SQLite/Row/SQLiteDataConvertible.swift index 78b6b1a..031bd41 100644 --- a/Sources/SQLite/Row/SQLiteDataConvertible.swift +++ b/Sources/SQLite/Row/SQLiteDataConvertible.swift @@ -1,5 +1,9 @@ +/// Capable of converting to and from `SQLiteData`. public protocol SQLiteDataConvertible { + /// Creates `Self` from `SQLiteData`. static func convertFromSQLiteData(_ data: SQLiteData) throws -> Self + + /// Converts `self` to `SQLiteData`. func convertToSQLiteData() throws -> SQLiteData } diff --git a/Sources/SQLite/Row/SQLiteDataType.swift b/Sources/SQLite/Row/SQLiteDataType.swift index 2d18ebf..02a7bb3 100644 --- a/Sources/SQLite/Row/SQLiteDataType.swift +++ b/Sources/SQLite/Row/SQLiteDataType.swift @@ -1,3 +1,4 @@ +/// Supported SQLite column data types when defining schemas. public enum SQLiteDataType: SQLDataType { /// See `SQLDataType`. public static func dataType(appropriateFor type: Any.Type) -> SQLiteDataType? { @@ -7,10 +8,19 @@ public enum SQLiteDataType: SQLDataType { return nil } + /// `INTEGER`. case integer + + /// `REAL`. case real + + /// `TEXT`. case text + + /// `BLOB`. case blob + + /// `NULL`. case null /// See `SQLSerializable`. diff --git a/Sources/SQLite/SQL/SQLiteBind.swift b/Sources/SQLite/SQL/SQLiteBind.swift index ba30acd..b3272dd 100644 --- a/Sources/SQLite/SQL/SQLiteBind.swift +++ b/Sources/SQLite/SQL/SQLiteBind.swift @@ -1,3 +1,4 @@ +/// SQLite specific `SQLBind`. public struct SQLiteBind: SQLBind { /// See `SQLBind`. public static func encodable(_ value: E) -> SQLiteBind @@ -10,11 +11,16 @@ public struct SQLiteBind: SQLBind { } } + /// Supported bind values. public enum Value { + /// A sub-expression. case expression(SQLiteExpression) + + /// Encodable value. case encodable(Encodable) } + /// Bind value. public var value: Value /// See `SQLSerializable`. diff --git a/Sources/SQLite/SQL/SQLiteBoolLiteral.swift b/Sources/SQLite/SQL/SQLiteBoolLiteral.swift index a7954e2..8972c53 100644 --- a/Sources/SQLite/SQL/SQLiteBoolLiteral.swift +++ b/Sources/SQLite/SQL/SQLiteBoolLiteral.swift @@ -1,3 +1,4 @@ +/// SQLite specific `SQLBoolLiteral`. public enum SQLiteBoolLiteral: SQLBoolLiteral { /// See `SQLBoolLiteral`. public static var `true`: SQLiteBoolLiteral { @@ -9,7 +10,10 @@ public enum SQLiteBoolLiteral: SQLBoolLiteral { return ._false } + /// See `SQLBoolLiteral`. case _true + + /// See `SQLBoolLiteral`. case _false /// See `SQLSerializable`. diff --git a/Sources/SQLite/SQL/SQLiteCollation.swift b/Sources/SQLite/SQL/SQLiteCollation.swift index 62345ed..4fa51e7 100644 --- a/Sources/SQLite/SQL/SQLiteCollation.swift +++ b/Sources/SQLite/SQL/SQLiteCollation.swift @@ -1,3 +1,4 @@ +/// SQLite specific `SQLCollation`. public enum SQLiteCollation: SQLCollation { /// See `SQLSerializable`. public func serialize(_ binds: inout [Encodable]) -> String { diff --git a/Sources/SQLite/SQL/SQLiteDefaultLiteral.swift b/Sources/SQLite/SQL/SQLiteDefaultLiteral.swift index 84b50bb..c78b293 100644 --- a/Sources/SQLite/SQL/SQLiteDefaultLiteral.swift +++ b/Sources/SQLite/SQL/SQLiteDefaultLiteral.swift @@ -1,3 +1,4 @@ +/// SQLite specific `SQLDefaultLiteral`. public struct SQLiteDefaultLiteral: SQLDefaultLiteral { /// See `SQLDefaultLiteral`. public static var `default`: SQLiteDefaultLiteral { diff --git a/Sources/SQLite/SQL/SQLiteDropIndex.swift b/Sources/SQLite/SQL/SQLiteDropIndex.swift index 7130e72..a69f78e 100644 --- a/Sources/SQLite/SQL/SQLiteDropIndex.swift +++ b/Sources/SQLite/SQL/SQLiteDropIndex.swift @@ -1,4 +1,6 @@ +/// SQLite specific `SQLDropIndex`. public struct SQLiteDropIndex: SQLDropIndex { + /// See `SQLDropIndex`. public var identifier: SQLiteIdentifier /// See `SQLSerializable`. @@ -10,6 +12,7 @@ public struct SQLiteDropIndex: SQLDropIndex { } } +/// SQLite specific drop index builder. public final class SQLiteDropIndexBuilder: SQLQueryBuilder where Connection: SQLConnection, Connection.Query == SQLiteQuery { @@ -33,6 +36,7 @@ public final class SQLiteDropIndexBuilder: SQLQueryBuilder extension SQLConnection where Query == SQLiteQuery { + /// Drops an index from a SQLite database. public func drop(index identifier: SQLiteIdentifier) -> SQLiteDropIndexBuilder { return .init(SQLiteDropIndex(identifier: identifier), on: self) } diff --git a/Sources/SQLite/SQL/SQLiteFunction.swift b/Sources/SQLite/SQL/SQLiteFunction.swift index ce868f7..7c1dc13 100644 --- a/Sources/SQLite/SQL/SQLiteFunction.swift +++ b/Sources/SQLite/SQL/SQLiteFunction.swift @@ -1,23 +1,32 @@ +/// SQLite specific `SQLFunction`. public struct SQLiteFunction: SQLFunction { + /// See `SQLFunction`. public typealias Argument = GenericSQLFunctionArgument + /// `COUNT(*)`. public static var count: SQLiteFunction { return .init(name: "COUNT", arguments: [.all]) } + /// See `SQLFunction`. public static func function(_ name: String, _ args: [Argument]) -> SQLiteFunction { return .init(name: name, arguments: args) } + /// See `SQLFunction`. public let name: String + + /// See `SQLFunction`. public let arguments: [Argument] + /// See `SQLSerializable`. public func serialize(_ binds: inout [Encodable]) -> String { return name + "(" + arguments.map { $0.serialize(&binds) }.joined(separator: ", ") + ")" } } extension SQLSelectExpression where Expression.Function == SQLiteFunction, Identifier == SQLiteIdentifier { + /// `COUNT(*) as ...`. public static func count(as alias: SQLiteIdentifier? = nil) -> Self { return .expression(.function(.count), alias: alias) } diff --git a/Sources/SQLite/SQL/SQLitePrimaryKey.swift b/Sources/SQLite/SQL/SQLitePrimaryKey.swift index 0a74de0..7771677 100644 --- a/Sources/SQLite/SQL/SQLitePrimaryKey.swift +++ b/Sources/SQLite/SQL/SQLitePrimaryKey.swift @@ -1,3 +1,4 @@ +/// SQLite specific `SQLPrimaryKeyDefault`. public enum SQLitePrimaryKeyDefault: SQLPrimaryKeyDefault { /// See `SQLPrimaryKey`. public static var `default`: SQLitePrimaryKeyDefault { diff --git a/Sources/SQLite/SQL/SQLiteQuery.swift b/Sources/SQLite/SQL/SQLiteQuery.swift index 1a61e3a..f15f644 100644 --- a/Sources/SQLite/SQL/SQLiteQuery.swift +++ b/Sources/SQLite/SQL/SQLiteQuery.swift @@ -130,6 +130,7 @@ public enum SQLiteQuery: SQLQuery { } extension SQLiteQuery: ExpressibleByStringLiteral { + /// See `ExpressibleByStringLiteral`. public init(stringLiteral value: String) { self = ._raw(value, []) } diff --git a/Sources/SQLite/SQL/SQLiteTable.swift b/Sources/SQLite/SQL/SQLiteTable.swift index b6e4bdd..46ff4d6 100644 --- a/Sources/SQLite/SQL/SQLiteTable.swift +++ b/Sources/SQLite/SQL/SQLiteTable.swift @@ -1 +1,2 @@ +/// SQLite specific `SQLTable`. public protocol SQLiteTable: SQLTable { } diff --git a/Sources/SQLite/Utilities/Deprecated.swift b/Sources/SQLite/Utilities/Deprecated.swift index 7567f5f..6e9b397 100644 --- a/Sources/SQLite/Utilities/Deprecated.swift +++ b/Sources/SQLite/Utilities/Deprecated.swift @@ -1,3 +1 @@ -/// - warning: Deprecated. -@available(*, deprecated, renamed: "SQLiteDataType") -public typealias SQLiteFieldType = SQLiteDataType +/// nothing here... yet diff --git a/Sources/SQLite/Utilities/SQLiteError.swift b/Sources/SQLite/Utilities/SQLiteError.swift index a4e37e2..f852062 100644 --- a/Sources/SQLite/Utilities/SQLiteError.swift +++ b/Sources/SQLite/Utilities/SQLiteError.swift @@ -8,9 +8,17 @@ import Debugging /// Errors that can be thrown while using SQLite public struct SQLiteError: Debuggable { let problem: Problem + + /// See `Debuggable`. public let reason: String + + /// See `Debuggable`. public var sourceLocation: SourceLocation? + + /// See `Debuggable`. public var stackTrace: [String] + + /// See `Debuggable`. public var identifier: String { return problem.rawValue }