mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
SQLiteral are passed via a literal parameter
This commit is contained in:
1 parent
aa6f55d72f
commit
637de8b6fa
24 files changed
+302
-303
No files matched your search
@@ -107,7 +107,7 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest {
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
public func select<RowDecoder>(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments), as: type)
|
||||
return select(literal: SQLLiteral(sql: sql, arguments: arguments), as: type)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*, and fetches values of
|
||||
@@ -137,8 +137,8 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest {
|
||||
/// as: String.self)
|
||||
/// let name: String? = try request.fetchOne(db)
|
||||
/// }
|
||||
public func select<RowDecoder>(_ sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return select(SQLSelectionLiteral(sqlLiteral), as: type)
|
||||
public func select<RowDecoder>(literal sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return select(SQLSelectionLiteral(literal: sqlLiteral), as: type)
|
||||
}
|
||||
|
||||
/// Creates a request which appends *selection*.
|
||||
@@ -372,15 +372,15 @@ extension TableRecord {
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select(sql: "id, email")
|
||||
public static func select(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return select(SQLLiteral(sql: sql, arguments: arguments))
|
||||
return select(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*.
|
||||
///
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select(SQLLiteral("id, email"))
|
||||
public static func select(_ sqlLiteral: SQLLiteral) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(sqlLiteral)
|
||||
/// let request = Player.select(literal: SQLLiteral("id, email"))
|
||||
public static func select(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(literal: sqlLiteral)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *selection*, and fetches values of
|
||||
@@ -416,7 +416,7 @@ extension TableRecord {
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
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)
|
||||
return all().select(literal: SQLLiteral(sql: sql, arguments: arguments), as: type)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*, and fetches values of
|
||||
@@ -424,11 +424,11 @@ extension TableRecord {
|
||||
///
|
||||
/// try dbQueue.read { db in
|
||||
/// // SELECT max(score) FROM player
|
||||
/// let request = Player.select(SQLLiteral("max(score)"), as: Int.self)
|
||||
/// let request = Player.select(literal: SQLLiteral("max(score)"), as: Int.self)
|
||||
/// let maxScore: Int? = try request.fetchOne(db)
|
||||
/// }
|
||||
public static func select<RowDecoder>(_ sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return all().select(sqlLiteral, as: type)
|
||||
public static func select<RowDecoder>(literal sqlLiteral: SQLLiteral, as type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return all().select(literal: sqlLiteral, as: type)
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate*.
|
||||
@@ -506,25 +506,25 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest<Self> {
|
||||
return filter(SQLLiteral(sql: sql, arguments: arguments))
|
||||
return filter(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate*.
|
||||
///
|
||||
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
|
||||
/// let request = Player.filter(SQLLiteral(sql: "email = ?", arguments: ["arthur@example.com"]))
|
||||
/// let request = Player.filter(literal: SQLLiteral(sql: "email = ?", arguments: ["arthur@example.com"]))
|
||||
///
|
||||
/// With Swift 5, you can safely embed raw values in your SQL queries,
|
||||
/// without any risk of syntax errors or SQL injection:
|
||||
///
|
||||
/// let request = Player.filter(SQLLiteral("email = \("arthur@example.com")))
|
||||
/// let request = Player.filter(literal: SQLLiteral("email = \("arthur@example.com")))
|
||||
///
|
||||
/// 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(_ sqlLiteral: SQLLiteral) -> QueryInterfaceRequest<Self> {
|
||||
public static func filter(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest<Self> {
|
||||
// NOT TESTED
|
||||
return all().filter(sqlLiteral)
|
||||
return all().filter(literal: sqlLiteral)
|
||||
}
|
||||
|
||||
/// Creates a request sorted according to the
|
||||
|
||||
Reference in new issue
Block a user