mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Drop obsolete MetalRow
This commit is contained in:
1 parent
4b049eefda
commit
dcbc5ef3f5
2 files changed
+1
-94
No files matched your search
@@ -18,27 +18,7 @@ class FetchPerformanceTests: XCTestCase {
|
||||
//
|
||||
// }
|
||||
|
||||
func testMetalRowFetchPerformance() {
|
||||
let databasePath = NSBundle(forClass: self.dynamicType).pathForResource("FetchPerformanceTests", ofType: "sqlite")!
|
||||
let dbQueue = try! DatabaseQueue(path: databasePath)
|
||||
|
||||
var sum: Int64 = 0
|
||||
self.measureBlock {
|
||||
dbQueue.inDatabase { db in
|
||||
for row in MetalRow.fetch(db, "SELECT * FROM items") {
|
||||
let i0: Int64 = row.value(atIndex: 0)
|
||||
let i1: Int64 = row.value(atIndex: 1)
|
||||
let i2: Int64 = row.value(atIndex: 2)
|
||||
let i3: Int64 = row.value(atIndex: 3)
|
||||
let i4: Int64 = row.value(atIndex: 4)
|
||||
sum += i0 + i1 + i2 + i3 + i4
|
||||
}
|
||||
}
|
||||
}
|
||||
XCTAssertEqual(sum, 4999990)
|
||||
}
|
||||
|
||||
func testRowMetalFetchPerformance() {
|
||||
func testMetalFetchPerformance() {
|
||||
let databasePath = NSBundle(forClass: self.dynamicType).pathForResource("FetchPerformanceTests", ofType: "sqlite")!
|
||||
let dbQueue = try! DatabaseQueue(path: databasePath)
|
||||
|
||||
|
||||
@@ -343,8 +343,6 @@ public struct Row: CollectionType {
|
||||
The returned generator is *unsafe* because it must be used with extra care,
|
||||
and GRDB.swift will not prevent invalid usage.
|
||||
|
||||
- It MUST be generated and iterated in the database queue.
|
||||
|
||||
- It MUST be iterated right away. Do not reserve it, do not wrap it in an
|
||||
Array.
|
||||
|
||||
@@ -598,74 +596,3 @@ public struct RowIndex: ForwardIndexType, BidirectionalIndexType, RandomAccessIn
|
||||
public func ==(lhs: RowIndex, rhs: RowIndex) -> Bool {
|
||||
return lhs.index == rhs.index
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MetalRow
|
||||
|
||||
public struct MetalRow {
|
||||
let sqliteStatement: SQLiteStatement
|
||||
|
||||
init(sqliteStatement: SQLiteStatement) {
|
||||
self.sqliteStatement = sqliteStatement
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Fetching From Database
|
||||
|
||||
/**
|
||||
Returns a row generator that provides fast but unsafe access to database
|
||||
values:
|
||||
|
||||
for row in MetalRow.fetch(db, "SELECT id, name FROM persons") {
|
||||
let id = row.int64(atIndex: 0)
|
||||
let name = row.string(atIndex: 1)
|
||||
}
|
||||
|
||||
The returned generator is *unsafe* because it must be used with extra care,
|
||||
and GRDB.swift will not prevent invalid usage.
|
||||
|
||||
- It MUST be generated and iterated in the database queue.
|
||||
|
||||
- It MUST be iterated right away. Do not reserve it, do not wrap it in an
|
||||
Array.
|
||||
|
||||
Granted with those constraints, the unsafe generator grants extra speed for
|
||||
the typed row accessors Row.int64(atIndex:), Row.string(atIndex:), etc.
|
||||
|
||||
- parameter db: A Database.
|
||||
- parameter sql: An SQL query.
|
||||
- parameter arguments: Optional statement arguments.
|
||||
- returns: A lazy sequence of rows.
|
||||
*/
|
||||
public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnyGenerator<MetalRow> {
|
||||
let statement = db.selectStatement(sql)
|
||||
return statement.metalGenerate(arguments: arguments) {
|
||||
MetalRow(sqliteStatement: statement.sqliteStatement)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Metal Row Values
|
||||
|
||||
public func value<Value: DatabaseValueConvertible>(atIndex index: Int) -> Value? {
|
||||
return Value.fromDatabaseValue(databaseValue(atIndex: index))
|
||||
}
|
||||
|
||||
public func value<Value: protocol<DatabaseValueConvertible, MetalType>>(atIndex index: Int) -> Value? {
|
||||
if sqlite3_column_type(sqliteStatement, Int32(index)) == SQLITE_NULL {
|
||||
return nil
|
||||
}
|
||||
return Value(sqliteStatement: sqliteStatement, index: Int32(index))
|
||||
}
|
||||
|
||||
public func value<Value: DatabaseValueConvertible>(atIndex index: Int) -> Value {
|
||||
return Value.fromDatabaseValue(databaseValue(atIndex: index))!
|
||||
}
|
||||
|
||||
public func value<Value: protocol<DatabaseValueConvertible, MetalType>>(atIndex index: Int) -> Value {
|
||||
return Value(sqliteStatement: sqliteStatement, index: Int32(index))
|
||||
}
|
||||
|
||||
func databaseValue(atIndex index: Int) -> DatabaseValue {
|
||||
return DatabaseValue(sqliteStatement: sqliteStatement, index: index)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user