mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
DatabaseValue adopts DatabaseValueConvertible
This commit is contained in:
1 parent
365c5fdab8
commit
c96c6b960c
5 files changed
+67
-1
No files matched your search
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// GRDB.swift
|
||||
// https://github.com/groue/GRDB.swift
|
||||
// Copyright (c) 2015 Gwendal Roué
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
|
||||
import XCTest
|
||||
import GRDB
|
||||
|
||||
class DatabaseValueTests: GRDBTestCase {
|
||||
|
||||
func testDatabaseValueAdoptsDatabaseValueConvertible() {
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE integers (integer INTEGER)")
|
||||
try db.execute("INSERT INTO integers (integer) VALUES (1)")
|
||||
let databaseValue: DatabaseValue = db.fetchOneRow("SELECT * FROM integers")!.value(named: "integer")! // Triggers DatabaseValue.init?(databaseValue: DatabaseValue)
|
||||
let count = db.fetchOne(Int.self, "SELECT COUNT(*) FROM integers WHERE integer = ?", arguments: [databaseValue])! // Triggers DatabaseValue.databaseValue
|
||||
XCTAssertEqual(count, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,8 @@
|
||||
56F0B9901B6001C600A2F135 /* DatabaseDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DatabaseDateComponentsTests.swift */; };
|
||||
56F0B9911B6001C600A2F135 /* DatabaseDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DatabaseDateTests.swift */; };
|
||||
56F0B9921B6001C600A2F135 /* DatabaseDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DatabaseDateTests.swift */; };
|
||||
56F691D31B97136500423970 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F691D21B97136500423970 /* DatabaseValueTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
56F691D41B97136500423970 /* DatabaseValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F691D21B97136500423970 /* DatabaseValueTests.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
9E903FA81B82729400A63DA0 /* DatabaseChanges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E903FA71B82729400A63DA0 /* DatabaseChanges.swift */; };
|
||||
9E903FA91B82741C00A63DA0 /* DatabaseChanges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E903FA71B82729400A63DA0 /* DatabaseChanges.swift */; };
|
||||
DC2393C81ABE35F8003FF113 /* GRDB-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -170,6 +172,7 @@
|
||||
56E5D7F91B4D422D00430942 /* GRDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
56F0B98D1B6001C600A2F135 /* DatabaseDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateComponentsTests.swift; sourceTree = "<group>"; };
|
||||
56F0B98E1B6001C600A2F135 /* DatabaseDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateTests.swift; sourceTree = "<group>"; };
|
||||
56F691D21B97136500423970 /* DatabaseValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueTests.swift; sourceTree = "<group>"; };
|
||||
9E903FA71B82729400A63DA0 /* DatabaseChanges.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseChanges.swift; sourceTree = "<group>"; };
|
||||
DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GRDB-Bridging.h"; sourceTree = "<group>"; };
|
||||
DC3773F319C8CBB3004FCF85 /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -270,6 +273,7 @@
|
||||
children = (
|
||||
5699796F1B539038005EBEED /* DatabaseValueConvertibleTests.swift */,
|
||||
569979701B539038005EBEED /* RawRepresentableTests.swift */,
|
||||
56F691D21B97136500423970 /* DatabaseValueTests.swift */,
|
||||
);
|
||||
path = DatabaseValueConvertible;
|
||||
sourceTree = "<group>";
|
||||
@@ -642,6 +646,7 @@
|
||||
56997A361B539038005EBEED /* DatabaseTests.swift in Sources */,
|
||||
56997A4E1B539038005EBEED /* PrimaryKeyNoneTests.swift in Sources */,
|
||||
56997A5A1B539038005EBEED /* RowModelInitializersTests.swift in Sources */,
|
||||
56F691D41B97136500423970 /* DatabaseValueTests.swift in Sources */,
|
||||
56997A401B539038005EBEED /* DatabaseValueConvertibleTests.swift in Sources */,
|
||||
56997A4C1B539038005EBEED /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
56F0B9921B6001C600A2F135 /* DatabaseDateTests.swift in Sources */,
|
||||
@@ -677,6 +682,7 @@
|
||||
56997A351B539038005EBEED /* DatabaseTests.swift in Sources */,
|
||||
56997A4D1B539038005EBEED /* PrimaryKeyNoneTests.swift in Sources */,
|
||||
56997A591B539038005EBEED /* RowModelInitializersTests.swift in Sources */,
|
||||
56F691D31B97136500423970 /* DatabaseValueTests.swift in Sources */,
|
||||
56997A3F1B539038005EBEED /* DatabaseValueConvertibleTests.swift in Sources */,
|
||||
56997A4B1B539038005EBEED /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
56F0B9911B6001C600A2F135 /* DatabaseDateTests.swift in Sources */,
|
||||
|
||||
@@ -130,3 +130,16 @@ public func ==(lhs: DatabaseValue, rhs: DatabaseValue) -> Bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/// DatabaseValue adopts DatabaseValueConvertible.
|
||||
extension DatabaseValue : DatabaseValueConvertible {
|
||||
/// Returns self
|
||||
public var databaseValue: DatabaseValue {
|
||||
return self
|
||||
}
|
||||
|
||||
/// Create a copy of `databaseValue`.
|
||||
public init?(databaseValue: DatabaseValue) {
|
||||
self = databaseValue
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
## Next version
|
||||
|
||||
**New**
|
||||
|
||||
- `DatabaseValue` adopts `DatabaseValueConvertible`, which allows the injection of a fetched value in another query without having to convert the raw database value into a regular Swift type.
|
||||
|
||||
|
||||
## 0.9.0
|
||||
|
||||
Released August 25, 2015
|
||||
|
||||
@@ -4,4 +4,3 @@
|
||||
- [ ] How can RowModel wrap two columns in a single CLLocationCoordinate2D property?
|
||||
- [ ] Find a purpose for methods that return a DatabaseValueConvertible? (Row.value(atIndex:), Row.value(named:), DatabaseValue.value()), or remove them.
|
||||
- [ ] Tests for DatabaseValue as Equatable
|
||||
- [ ] Make sure DatabaseValue is DatabaseValueConvertible, and write a test that chains two requests, the second one using a databaseValue from the first as an argument.
|
||||
Reference in new issue
Block a user