DatabaseValueConvertible
public protocol DatabaseValueConvertible : SQLExpressibleTypes that adopt DatabaseValueConvertible can be initialized from database values.
The protocol comes with built-in methods that allow to fetch cursors, arrays, or single values:
try String.fetchCursor(db, sql: "SELECT name FROM ...", arguments:...) // Cursor of String
try String.fetchAll(db, sql: "SELECT name FROM ...", arguments:...)    // [String]
try String.fetchOne(db, sql: "SELECT name FROM ...", arguments:...)    // String?
let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...")
try String.fetchCursor(statement, arguments:...) // Cursor of String
try String.fetchAll(statement, arguments:...)    // [String]
try String.fetchOne(statement, arguments:...)    // String?
DatabaseValueConvertible is adopted by Bool, Int, String, etc.
- 
                  databaseValueDefault implementationReturns a value that can be stored in the database. Default ImplementationReturns a value that can be stored in the database. DeclarationSwift var databaseValue: DatabaseValue { get }
- 
                  fromDatabaseValue(_:)Default implementationReturns a value initialized from dbValue, if possible. Default ImplementationReturns a value initialized from dbValue, if possible. DeclarationSwift static func fromDatabaseValue(_ dbValue: DatabaseValue) -> `Self`?
- 
                  fetchCursor(_:arguments:adapter:)Extension methodReturns a cursor over values fetched from a prepared statement. let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") let names = try String.fetchCursor(statement) // Cursor of String while let name = try names.next() { // String ... }If the database is modified during the cursor iteration, the remaining elements are undefined. The cursor must be iterated in a protected dispath queue. Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchCursor( _ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self>ParametersstatementThe statement to run. argumentsOptional statement arguments. adapterOptional RowAdapter Return ValueA cursor over fetched values. 
- 
                  fetchAll(_:arguments:adapter:)Extension methodReturns an array of values fetched from a prepared statement. let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") let names = try String.fetchAll(statement) // [String]Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchAll( _ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self]ParametersstatementThe statement to run. argumentsOptional statement arguments. adapterOptional RowAdapter Return ValueAn array. 
- 
                  fetchOne(_:arguments:adapter:)Extension methodReturns a single value fetched from a prepared statement. The result is nil if the query returns no row, or if no value can be extracted from the first row. let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") let name = try String.fetchOne(statement) // String?Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchOne( _ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self?ParametersstatementThe statement to run. argumentsOptional statement arguments. adapterOptional RowAdapter Return ValueAn optional value. 
- 
                  fetchCursor(_:sql:arguments:adapter:)Extension methodReturns a cursor over values fetched from an SQL query. let names = try String.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String while let name = try name.next() { // String ... }If the database is modified during the cursor iteration, the remaining elements are undefined. The cursor must be iterated in a protected dispath queue. Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchCursor( _ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor<Self>ParametersdbA database connection. sqlAn SQL query. argumentsStatement arguments. adapterOptional RowAdapter Return ValueA cursor over fetched values. 
- 
                  fetchAll(_:sql:arguments:adapter:)Extension methodReturns an array of values fetched from an SQL query. let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String]Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchAll( _ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self]ParametersdbA database connection. sqlAn SQL query. argumentsStatement arguments. adapterOptional RowAdapter Return ValueAn array. 
- 
                  fetchOne(_:sql:arguments:adapter:)Extension methodReturns a single value fetched from an SQL query. The result is nil if the query returns no row, or if no value can be extracted from the first row. let name = try String.fetchOne(db, sql: "SELECT name FROM ...") // String?Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchOne( _ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self?ParametersdbA database connection. sqlAn SQL query. argumentsStatement arguments. adapterOptional RowAdapter Return ValueAn optional value. 
- 
                  fetchCursor(_:_:)Extension methodReturns a cursor over values fetched from a fetch request. let request = Player.select(Column("name")) let names = try String.fetchCursor(db, request) // Cursor of String while let name = try name.next() { // String ... }If the database is modified during the cursor iteration, the remaining elements are undefined. The cursor must be iterated in a protected dispath queue. Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchCursor<R>(_ db: Database, _ request: R) throws -> DatabaseValueCursor<Self> where R : FetchRequestParametersdbA database connection. requestA FetchRequest. Return ValueA cursor over fetched values. 
- 
                  fetchAll(_:_:)Extension methodReturns an array of values fetched from a fetch request. let request = Player.select(Column("name")) let names = try String.fetchAll(db, request) // [String]Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchAll<R>(_ db: Database, _ request: R) throws -> [Self] where R : FetchRequestParametersdbA database connection. requestA FetchRequest. Return ValueAn array. 
- 
                  fetchOne(_:_:)Extension methodReturns a single value fetched from a fetch request. The result is nil if the query returns no row, or if no value can be extracted from the first row. let request = Player.filter(key: 1).select(Column("name")) let name = try String.fetchOne(db, request) // String?Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchOne<R>(_ db: Database, _ request: R) throws -> Self? where R : FetchRequestParametersdbA database connection. requestA FetchRequest. Return ValueAn optional value. 
- 
                  fetchCursor(_:arguments:adapter:)Extension methodReturns a cursor over values fetched from a prepared statement. let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") let names = try String.fetchCursor(statement) // Cursor of String while let name = try names.next() { // String ... }If the database is modified during the cursor iteration, the remaining elements are undefined. The cursor must be iterated in a protected dispath queue. Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchCursor( _ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor<Self>ParametersstatementThe statement to run. argumentsOptional statement arguments. adapterOptional RowAdapter Return ValueA cursor over fetched values. 
- 
                  fetchAll(_:arguments:adapter:)Extension methodReturns an array of values fetched from a prepared statement. let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") let names = try String.fetchAll(statement) // [String]Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchAll( _ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self]ParametersstatementThe statement to run. argumentsOptional statement arguments. adapterOptional RowAdapter Return ValueAn array of values. 
- 
                  fetchOne(_:arguments:adapter:)Extension methodReturns a single value fetched from a prepared statement. let statement = try db.makeSelectStatement(sql: "SELECT name FROM ...") let name = try String.fetchOne(statement) // String?Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchOne( _ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self?ParametersstatementThe statement to run. argumentsOptional statement arguments. adapterOptional RowAdapter Return ValueAn optional value. 
- 
                  fetchCursor(_:sql:arguments:adapter:)Extension methodReturns a cursor over values fetched from an SQL query. let names = try String.fetchCursor(db, sql: "SELECT name FROM ...") // Cursor of String while let name = try names.next() { // String ... }If the database is modified during the cursor iteration, the remaining elements are undefined. The cursor must be iterated in a protected dispath queue. Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchCursor( _ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor<Self>ParametersdbA database connection. sqlAn SQL query. argumentsStatement arguments. adapterOptional RowAdapter Return ValueA cursor over fetched values. 
- 
                  fetchAll(_:sql:arguments:adapter:)Extension methodReturns an array of values fetched from an SQL query. let names = try String.fetchAll(db, sql: "SELECT name FROM ...") // [String]Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchAll( _ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self]ParametersdbA database connection. sqlAn SQL query. argumentsStatement arguments. adapterOptional RowAdapter Return ValueAn array of values. 
- 
                  fetchOne(_:sql:arguments:adapter:)Extension methodReturns a single value fetched from an SQL query. let name = try String.fetchOne(db, sql: "SELECT name FROM ...") // String?Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchOne( _ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self?ParametersdbA database connection. sqlAn SQL query. argumentsStatement arguments. adapterOptional RowAdapter Return ValueAn optional value. 
- 
                  fetchCursor(_:_:)Extension methodReturns a cursor over values fetched from a fetch request. let request = Player.select(Column("name")) let names = try String.fetchCursor(db, request) // Cursor of String while let name = try names.next() { // String ... }If the database is modified during the cursor iteration, the remaining elements are undefined. The cursor must be iterated in a protected dispath queue. Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchCursor<R: FetchRequest>(_ db: Database, _ request: R) throws -> FastDatabaseValueCursor<Self>ParametersdbA database connection. requestA FetchRequest. Return ValueA cursor over fetched values. 
- 
                  fetchAll(_:_:)Extension methodReturns an array of values fetched from a fetch request. let request = Player.select(Column("name")) let names = try String.fetchAll(db, request) // [String]Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchAll<R>(_ db: Database, _ request: R) throws -> [Self] where R : FetchRequestParametersdbA database connection. requestA FetchRequest. Return ValueAn array of values. 
- 
                  fetchOne(_:_:)Extension methodReturns a single value fetched from a fetch request. let request = Player.filter(key: 1).select(Column("name")) let name = try String.fetchOne(db, request) // String?Throws A DatabaseError is thrown whenever an SQLite error occurs.DeclarationSwift public static func fetchOne<R>(_ db: Database, _ request: R) throws -> Self? where R : FetchRequestParametersdbA database connection. requestA FetchRequest. Return ValueAn optional value. 
 View on GitHub
View on GitHub Install in Dash
Install in Dash DatabaseValueConvertible Protocol Reference
        DatabaseValueConvertible Protocol Reference