mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Statement arguments are generally non optional
This commit is contained in:
1 parent
f018c7f823
commit
aa6f55d72f
17 files changed
+95
-130
No files matched your search
@@ -3610,7 +3610,7 @@
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
@@ -3657,7 +3657,7 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 5.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
|
||||
@@ -123,12 +123,11 @@ extension Database {
|
||||
///
|
||||
/// - parameters:
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func execute(_ sql: String, arguments: StatementArguments? = nil) throws {
|
||||
public func execute(_ sql: String, arguments: StatementArguments = StatementArguments()) throws {
|
||||
// TODO: force sql parameter name: execute(sql:...)
|
||||
// TODO: make arguments non optional
|
||||
try execute(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
try execute(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Executes one or several SQL statements, separated by semi-colons.
|
||||
|
||||
@@ -253,14 +253,13 @@ extension DatabaseValueConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self> {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self> {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
@@ -270,14 +269,13 @@ extension DatabaseValueConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
@@ -290,14 +288,13 @@ extension DatabaseValueConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,14 +578,13 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped> {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor<Wrapped> {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
@@ -598,14 +594,13 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - parameter arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-12
@@ -744,14 +744,13 @@ extension Row {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of rows fetched from an SQL query.
|
||||
@@ -765,14 +764,13 @@ extension Row {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row] {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single row fetched from an SQL query.
|
||||
@@ -786,14 +784,13 @@ extension Row {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row? {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,16 +14,14 @@ public struct SQLInterpolation: StringInterpolationProtocol {
|
||||
}
|
||||
|
||||
/// "SELECT * FROM player"
|
||||
public mutating func appendLiteral(_ literal: String) {
|
||||
sql += literal
|
||||
public mutating func appendLiteral(_ sql: String) {
|
||||
self.sql += sql
|
||||
}
|
||||
|
||||
/// "SELECT * FROM \(raw: "player")"
|
||||
public mutating func appendInterpolation(sql literal: String, arguments: StatementArguments? = nil) {
|
||||
sql += literal
|
||||
if let arguments = arguments {
|
||||
self.arguments += arguments
|
||||
}
|
||||
public mutating func appendInterpolation(sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self.sql += sql
|
||||
self.arguments += arguments
|
||||
}
|
||||
|
||||
/// "SELECT * FROM player WHERE \(condition)"
|
||||
|
||||
@@ -29,11 +29,9 @@ extension SQLLiteral {
|
||||
self += other
|
||||
}
|
||||
|
||||
public mutating func append(sql: String, arguments: StatementArguments? = nil) {
|
||||
public mutating func append(sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
self.sql += sql
|
||||
if let arguments = arguments {
|
||||
self.arguments += arguments
|
||||
}
|
||||
self.arguments += arguments
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,14 @@ public struct SQLRequest<T> : FetchRequest {
|
||||
///
|
||||
/// - parameters:
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter.
|
||||
/// - cached: Defaults to false. If true, the request reuses a cached
|
||||
/// prepared statement.
|
||||
/// - returns: A SQLRequest
|
||||
public init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) {
|
||||
// TODO: make arguments non optional
|
||||
public init(_ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false) {
|
||||
// TODO: force sql parameter name: init(sql:...)
|
||||
self.init(SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter, fromCache: cached ? .public : nil)
|
||||
self.init(SQLLiteral(sql: sql, arguments: arguments), adapter: adapter, fromCache: cached ? .public : nil)
|
||||
}
|
||||
|
||||
/// Creates a request from an SQLLiteral, and optional row adapter.
|
||||
|
||||
@@ -465,7 +465,7 @@ public final class UpdateStatement : Statement {
|
||||
|
||||
/// Executes the SQL query.
|
||||
///
|
||||
/// - parameter arguments: Statement arguments.
|
||||
/// - parameter arguments: Optional statement arguments.
|
||||
/// - throws: A DatabaseError whenever an SQLite error occurs.
|
||||
public func execute(arguments: StatementArguments? = nil) throws {
|
||||
SchedulingWatchdog.preconditionValidQueue(database)
|
||||
|
||||
@@ -241,14 +241,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor<Self> {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor<Self> {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of values fetched from an SQL query.
|
||||
@@ -258,14 +257,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single value fetched from an SQL query.
|
||||
@@ -275,14 +273,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,14 +559,13 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor<Wrapped> {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor<Wrapped> {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of optional values fetched from an SQL query.
|
||||
@@ -579,14 +575,13 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - parameter arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of optional values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,9 +106,8 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest {
|
||||
/// let request = Player.all().select(sql: "max(score)", as: Int.self)
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
public func select<RowDecoder>(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
// TODO: make arguments non optional
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments ?? .init()), as: type)
|
||||
public func select<RowDecoder>(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments), as: type)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*, and fetches values of
|
||||
@@ -372,9 +371,8 @@ extension TableRecord {
|
||||
///
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select(sql: "id, email")
|
||||
public static func select(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> {
|
||||
// TODO: make arguments non optional
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
public static func select(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*.
|
||||
@@ -417,9 +415,8 @@ extension TableRecord {
|
||||
/// let request = Player.select(sql: "max(score)", as: Int.self)
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
public static func select<RowDecoder>(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
// TODO: make arguments non optional
|
||||
return all().select(SQLLiteral(sql: sql, arguments: arguments ?? .init()), as: type)
|
||||
public static func select<RowDecoder>(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return all().select(SQLLiteral(sql: sql, arguments: arguments), as: type)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*, and fetches values of
|
||||
@@ -508,9 +505,8 @@ extension TableRecord {
|
||||
/// The selection defaults to all columns. This default can be changed for
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func filter(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> {
|
||||
// TODO: make arguments non optional
|
||||
return filter(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
public static func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return filter(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate*.
|
||||
@@ -580,7 +576,7 @@ extension TableRecord {
|
||||
/// The selection defaults to all columns. This default can be changed for
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func order(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> {
|
||||
public static func order(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(sql: sql, arguments: arguments)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,8 @@ extension SelectionRequest {
|
||||
/// request
|
||||
/// .select(sql: "id")
|
||||
/// .select(sql: "email")
|
||||
public func select(sql: String, arguments: StatementArguments? = nil) -> Self {
|
||||
// TODO: make arguments non optional
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
public func select(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*.
|
||||
@@ -122,9 +121,8 @@ extension FilteredRequest {
|
||||
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
|
||||
/// var request = Player.all()
|
||||
/// request = request.filter(sql: "email = ?", arguments: ["arthur@example.com"])
|
||||
public func filter(sql: String, arguments: StatementArguments? = nil) -> Self {
|
||||
// TODO: make arguments non optional
|
||||
return filter(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
public func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return filter(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate* added to the
|
||||
@@ -322,9 +320,8 @@ extension AggregatingRequest {
|
||||
}
|
||||
|
||||
/// Creates a request with a new grouping.
|
||||
public func group(sql: String, arguments: StatementArguments? = nil) -> Self {
|
||||
// TODO: make arguments non optional
|
||||
return group(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
public func group(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return group(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with a new grouping.
|
||||
@@ -345,9 +342,8 @@ extension AggregatingRequest {
|
||||
|
||||
/// Creates a request with the provided *sql* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
public func having(sql: String, arguments: StatementArguments? = nil) -> Self {
|
||||
// TODO: make arguments non optional
|
||||
return having(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
public func having(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return having(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *sql* added to the
|
||||
@@ -443,9 +439,8 @@ extension OrderedRequest {
|
||||
/// request
|
||||
/// .order(sql: "email")
|
||||
/// .order(sql: "name")
|
||||
public func order(sql: String, arguments: StatementArguments? = nil) -> Self {
|
||||
// TODO: make arguments non optional
|
||||
return order(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
public func order(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return order(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *sql* used for sorting.
|
||||
|
||||
@@ -49,10 +49,9 @@ public struct SQLExpressionLiteral : SQLExpression {
|
||||
/// SQLExpressionLiteral("1 + 2")
|
||||
/// SQLExpressionLiteral("? + ?", arguments: [1, 2])
|
||||
/// SQLExpressionLiteral(":one + :two", arguments: ["one": 1, "two": 2])
|
||||
public init(_ sql: String, arguments: StatementArguments? = nil) {
|
||||
// TODO: make arguments non optional
|
||||
public init(_ sql: String, arguments: StatementArguments = StatementArguments()) {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
self.init(SQLLiteral(sql: sql, arguments: arguments ?? .init()))
|
||||
self.init(SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
|
||||
@@ -212,14 +212,13 @@ extension FetchableRecord {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor<Self> {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor<Self> {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns an array of records fetched from an SQL query.
|
||||
@@ -229,14 +228,13 @@ extension FetchableRecord {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
/// Returns a single record fetched from an SQL query.
|
||||
@@ -246,14 +244,13 @@ extension FetchableRecord {
|
||||
/// - parameters:
|
||||
/// - db: A database connection.
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - arguments: Statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? {
|
||||
// TODO: make arguments non optional
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public final class FetchedRecordsController<Record: FetchableRecord> {
|
||||
public convenience init(
|
||||
_ databaseWriter: DatabaseWriter,
|
||||
sql: String,
|
||||
arguments: StatementArguments? = nil,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: RowAdapter? = nil,
|
||||
queue: DispatchQueue = .main,
|
||||
isSameRecord: ((Record, Record) -> Bool)? = nil) throws
|
||||
@@ -196,7 +196,7 @@ public final class FetchedRecordsController<Record: FetchableRecord> {
|
||||
///
|
||||
/// This method must be used from the controller's dispatch queue (the
|
||||
/// main queue unless stated otherwise in the controller's initializer).
|
||||
public func setRequest(sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws {
|
||||
public func setRequest(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws {
|
||||
try setRequest(SQLRequest(sql, arguments: arguments, adapter: adapter))
|
||||
}
|
||||
|
||||
@@ -429,7 +429,7 @@ extension FetchedRecordsController where Record: TableRecord {
|
||||
public convenience init(
|
||||
_ databaseWriter: DatabaseWriter,
|
||||
sql: String,
|
||||
arguments: StatementArguments? = nil,
|
||||
arguments: StatementArguments = StatementArguments(),
|
||||
adapter: RowAdapter? = nil,
|
||||
queue: DispatchQueue = .main) throws
|
||||
{
|
||||
|
||||
@@ -3615,7 +3615,7 @@
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
@@ -3662,7 +3662,7 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 5.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
|
||||
@@ -2637,7 +2637,7 @@
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
@@ -2684,7 +2684,7 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 5.0;
|
||||
SWIFT_VERSION = 4.2;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
|
||||
@@ -386,20 +386,17 @@ extension MyDatabaseDecoder {
|
||||
|
||||
// MARK: - Fetch from SQL
|
||||
|
||||
static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> MapCursor<RowCursor, DecodedType> {
|
||||
// TODO: make arguments non optional
|
||||
static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> MapCursor<RowCursor, DecodedType> {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [DecodedType] {
|
||||
// TODO: make arguments non optional
|
||||
static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [DecodedType] {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DecodedType? {
|
||||
// TODO: make arguments non optional
|
||||
static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DecodedType? {
|
||||
// TODO: force sql parameter name: fetchCursor(db, sql:...)
|
||||
return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user