mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
filter(id:) does not accept optionals
This commit is contained in:
1 parent
2625653532
commit
09899e9bcf
8 files changed
+14
-102
No files matched your search
@@ -334,7 +334,7 @@ where Self: FilteredRequest,
|
||||
/// let request = try Player...filter(id: 1)
|
||||
///
|
||||
/// - parameter id: A primary key
|
||||
public func filter(id: RowDecoder.ID?) -> Self {
|
||||
public func filter(id: RowDecoder.ID) -> Self {
|
||||
filter(key: id)
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ where Self: FilteredRequest,
|
||||
/// let request = try Player...filter(id: 1)
|
||||
///
|
||||
/// - parameter id: A primary key
|
||||
public func filter(id: RowDecoder.ID.Wrapped?) -> Self {
|
||||
public func filter(id: RowDecoder.ID.Wrapped) -> Self {
|
||||
filter(key: id)
|
||||
}
|
||||
|
||||
|
||||
@@ -364,9 +364,7 @@ extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
|
||||
/// let request = Player.filter(id: 1)
|
||||
///
|
||||
/// - parameter id: A primary key
|
||||
public static func filter(id: ID?)
|
||||
-> QueryInterfaceRequest<Self>
|
||||
{
|
||||
public static func filter(id: ID) -> QueryInterfaceRequest<Self> {
|
||||
all().filter(id: id)
|
||||
}
|
||||
|
||||
@@ -392,9 +390,7 @@ extension TableRecord where Self: Identifiable, ID: _OptionalProtocol, ID.Wrappe
|
||||
/// let request = Player.filter(id: 1)
|
||||
///
|
||||
/// - parameter id: A primary key
|
||||
public static func filter(id: ID.Wrapped?)
|
||||
-> QueryInterfaceRequest<Self>
|
||||
{
|
||||
public static func filter(id: ID.Wrapped) -> QueryInterfaceRequest<Self> {
|
||||
all().filter(id: id)
|
||||
}
|
||||
|
||||
|
||||
@@ -202,14 +202,8 @@ extension FetchableRecord where Self: TableRecord & Identifiable, ID: DatabaseVa
|
||||
/// - id: A primary key value.
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, id: ID?)
|
||||
throws -> Self?
|
||||
{
|
||||
guard let id = id else {
|
||||
// Avoid hitting the database
|
||||
return nil
|
||||
}
|
||||
return try filter(id: id).fetchOne(db)
|
||||
public static func fetchOne(_ db: Database, id: ID) throws -> Self? {
|
||||
try filter(id: id).fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,14 +268,8 @@ where Self: TableRecord & Identifiable,
|
||||
/// - id: A primary key value.
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database, id: ID.Wrapped?)
|
||||
throws -> Self?
|
||||
{
|
||||
guard let id = id else {
|
||||
// Avoid hitting the database
|
||||
return nil
|
||||
}
|
||||
return try filter(id: id).fetchOne(db)
|
||||
public static func fetchOne(_ db: Database, id: ID.Wrapped) throws -> Self? {
|
||||
try filter(id: id).fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -697,14 +697,8 @@ extension MutablePersistableRecord where Self: Identifiable, ID: DatabaseValueCo
|
||||
/// - id: A primary key value.
|
||||
/// - returns: Whether a database row was deleted.
|
||||
@discardableResult
|
||||
public static func deleteOne(_ db: Database, id: ID?)
|
||||
throws -> Bool
|
||||
{
|
||||
guard let id = id else {
|
||||
// Avoid hitting the database
|
||||
return false
|
||||
}
|
||||
return try deleteAll(db, ids: [id]) > 0
|
||||
public static func deleteOne(_ db: Database, id: ID) throws -> Bool {
|
||||
try deleteAll(db, ids: [id]) > 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -767,14 +761,8 @@ where Self: Identifiable,
|
||||
/// - id: A primary key value.
|
||||
/// - returns: Whether a database row was deleted.
|
||||
@discardableResult
|
||||
public static func deleteOne(_ db: Database, id: ID.Wrapped?)
|
||||
throws -> Bool
|
||||
{
|
||||
guard let id = id else {
|
||||
// Avoid hitting the database
|
||||
return false
|
||||
}
|
||||
return try deleteAll(db, ids: [id]) > 0
|
||||
public static func deleteOne(_ db: Database, id: ID.Wrapped) throws -> Bool {
|
||||
try deleteAll(db, ids: [id]) > 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -562,14 +562,6 @@ class RecordMinimalNonOptionalPrimaryKeySingleTests: GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
// nil id
|
||||
let id: String? = nil
|
||||
let fetchedRecord = try MinimalNonOptionalPrimaryKeySingle.fetchOne(db, id: id)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
// non-nil id
|
||||
let fetchedRecord = try MinimalNonOptionalPrimaryKeySingle.fetchOne(db, id: record.id)!
|
||||
XCTAssertTrue(fetchedRecord.id == record.id)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE \"id\" = '\(record.id)'")
|
||||
@@ -717,14 +709,6 @@ class RecordMinimalNonOptionalPrimaryKeySingleTests: GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
// nil id
|
||||
let id: String? = nil
|
||||
let fetchedRecord = try MinimalNonOptionalPrimaryKeySingle.filter(id: id).fetchOne(db)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
// non-nil id
|
||||
let fetchedRecord = try MinimalNonOptionalPrimaryKeySingle.filter(id: record.id).fetchOne(db)!
|
||||
XCTAssertTrue(fetchedRecord.id == record.id)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE \"id\" = '\(record.id)'")
|
||||
|
||||
@@ -595,14 +595,6 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
// nil id
|
||||
let id: Int64? = nil
|
||||
let fetchedRecord = try MinimalRowID.fetchOne(db, id: id)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
// non-nil id
|
||||
let fetchedRecord = try MinimalRowID.fetchOne(db, id: record.id!)!
|
||||
XCTAssertTrue(fetchedRecord.id == record.id)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalRowIDs\" WHERE \"id\" = \(record.id!)")
|
||||
@@ -750,14 +742,6 @@ class RecordMinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
// nil id
|
||||
let id: Int64? = nil
|
||||
let fetchedRecord = try MinimalRowID.filter(id: id).fetchOne(db)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
// non-nil id
|
||||
let fetchedRecord = try MinimalRowID.filter(id: record.id!).fetchOne(db)!
|
||||
XCTAssertTrue(fetchedRecord.id == record.id)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalRowIDs\" WHERE \"id\" = \(record.id!)")
|
||||
|
||||
@@ -624,14 +624,6 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
// nil id
|
||||
let id: String? = nil
|
||||
let fetchedRecord = try MinimalSingle.fetchOne(db, id: id)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
// non-nil id
|
||||
let fetchedRecord = try MinimalSingle.fetchOne(db, id: record.UUID!)!
|
||||
XCTAssertTrue(fetchedRecord.UUID == record.UUID)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE \"UUID\" = '\(record.UUID!)'")
|
||||
@@ -786,14 +778,6 @@ class RecordMinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
// nil id
|
||||
let id: String? = nil
|
||||
let fetchedRecord = try MinimalSingle.filter(id: id).fetchOne(db)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
// non-nil id
|
||||
let fetchedRecord = try MinimalSingle.filter(id: record.UUID!).fetchOne(db)!
|
||||
XCTAssertTrue(fetchedRecord.UUID == record.UUID)
|
||||
XCTAssertEqual(lastSQLQuery, "SELECT * FROM \"minimalSingles\" WHERE \"UUID\" = '\(record.UUID!)'")
|
||||
|
||||
@@ -689,13 +689,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
let id: Int64? = nil
|
||||
let fetchedRecord = try Person.fetchOne(db, id: id)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
let fetchedRecord = try Person.fetchOne(db, id: record.id)!
|
||||
let fetchedRecord = try Person.fetchOne(db, id: record.id!)!
|
||||
XCTAssertTrue(fetchedRecord.id == record.id)
|
||||
XCTAssertTrue(fetchedRecord.name == record.name)
|
||||
XCTAssertTrue(fetchedRecord.age == record.age)
|
||||
@@ -848,13 +842,7 @@ class RecordPrimaryKeyHiddenRowIDTests : GRDBTestCase {
|
||||
|
||||
if #available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6, *) {
|
||||
do {
|
||||
let id: Int64? = nil
|
||||
let fetchedRecord = try Person.filter(id: id).fetchOne(db)
|
||||
XCTAssertTrue(fetchedRecord == nil)
|
||||
}
|
||||
|
||||
do {
|
||||
let fetchedRecord = try Person.filter(id: record.id).fetchOne(db)!
|
||||
let fetchedRecord = try Person.filter(id: record.id!).fetchOne(db)!
|
||||
XCTAssertTrue(fetchedRecord.id == record.id)
|
||||
XCTAssertTrue(fetchedRecord.name == record.name)
|
||||
XCTAssertTrue(fetchedRecord.age == record.age)
|
||||
|
||||
Reference in new issue
Block a user