SQLRequest
public struct SQLRequest<RowDecoder>
extension SQLRequest: FetchRequest
extension SQLRequest: ExpressibleByStringInterpolation
A FetchRequest built from raw SQL.
-
The request adapter
Declaration
Swift
public var adapter: RowAdapter?
-
Creates a request from an SQL string, optional arguments, and optional row adapter.
let request = SQLRequest<String>(sql: """ SELECT name FROM player """) let request = SQLRequest<Player>(sql: """ SELECT * FROM player WHERE id = ? """, arguments: [1])
Declaration
Swift
public init( sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false)
Parameters
sql
An SQL query.
arguments
Statement arguments.
adapter
Optional RowAdapter.
cached
Defaults to false. If true, the request reuses a cached prepared statement.
Return Value
A SQLRequest
-
Creates a request from an
SQL
literal, and optional row adapter.Literals allow you to safely embed raw values in your SQL, without any risk of syntax errors or SQL injection:
let name = "O'brien" let request = SQLRequest<Player>(literal: """ SELECT * FROM player WHERE name = \(name) """)
Declaration
Swift
public init(literal sqlLiteral: SQL, adapter: RowAdapter? = nil, cached: Bool = false)
Parameters
sqlLiteral
An
SQL
literal.adapter
Optional RowAdapter.
cached
Defaults to false. If true, the request reuses a cached prepared statement.
Return Value
A SQLRequest
-
Undocumented
Declaration
Swift
public var sqlSubquery: SQLSubquery { get }
-
Declaration
Swift
public func fetchCount(_ db: Database) throws -> Int
-
Declaration
Swift
public func makePreparedRequest( _ db: Database, forSingleResult singleResult: Bool = false) throws -> PreparedRequest
-
:nodoc
Declaration
Swift
public init(unicodeScalarLiteral: String)
-
Creates a request from an SQL string, optional arguments, and optional row adapter.
let request = SQLRequest(sql: """ SELECT * FROM player WHERE id = ? """, arguments: [1])
Declaration
Swift
public init( sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false)
Parameters
sql
An SQL query.
arguments
Statement arguments.
adapter
Optional RowAdapter.
cached
Defaults to false. If true, the request reuses a cached prepared statement.
Return Value
A SQLRequest
-
Creates a request from an
SQL
literal, and optional row adapter.Literals allow you to safely embed raw values in your SQL, without any risk of syntax errors or SQL injection:
let name = "O'brien" let request = SQLRequest(literal: """ SELECT * FROM player WHERE name = \(name) """)
Declaration
Swift
public init(literal sqlLiteral: SQL, adapter: RowAdapter? = nil, cached: Bool = false)
Parameters
sqlLiteral
An
SQL
literal.adapter
Optional RowAdapter.
cached
Defaults to false. If true, the request reuses a cached prepared statement.
Return Value
A SQLRequest