Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffmacd committed Jul 2, 2022
1 parent c4bdad8 commit abff512
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions Sources/SQLite/Typed/Coding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,39 +216,39 @@ private class SQLiteEncoder: Encoder {

func encodeIfPresent(_ value: Int?, forKey key: SQLiteEncoder.SQLiteKeyedEncodingContainer<Key>.Key) throws {
if let value = value {
encoder.setters.append(Expression(key.stringValue) <- value)
try encode(value, forKey: key)
} else if forcingNilValueSetters {
encoder.setters.append(Expression<Int?>(key.stringValue) <- nil)
}
}

func encodeIfPresent(_ value: Bool?, forKey key: Key) throws {
if let value = value {
encoder.setters.append(Expression(key.stringValue) <- value)
try encode(value, forKey: key)
} else if forcingNilValueSetters {
encoder.setters.append(Expression<Bool?>(key.stringValue) <- nil)
}
}

func encodeIfPresent(_ value: Float?, forKey key: Key) throws {
if let value = value {
encoder.setters.append(Expression(key.stringValue) <- Double(value))
try encode(value, forKey: key)
} else if forcingNilValueSetters {
encoder.setters.append(Expression<Double?>(key.stringValue) <- nil)
}
}

func encodeIfPresent(_ value: Double?, forKey key: Key) throws {
if let value = value {
encoder.setters.append(Expression(key.stringValue) <- value)
try encode(value, forKey: key)
} else if forcingNilValueSetters {
encoder.setters.append(Expression<Double?>(key.stringValue) <- nil)
}
}

func encodeIfPresent(_ value: String?, forKey key: MyKey) throws {
if let value = value {
encoder.setters.append(Expression(key.stringValue) <- value)
try encode(value, forKey: key)
} else if forcingNilValueSetters {
encoder.setters.append(Expression<String?>(key.stringValue) <- nil)
}
Expand Down Expand Up @@ -277,18 +277,7 @@ private class SQLiteEncoder: Encoder {
encoder.setters.append(Expression<String?>(key.stringValue) <- nil)
return
}
switch value {
case let data as Data:
encoder.setters.append(Expression(key.stringValue) <- data)
case let date as Date:
encoder.setters.append(Expression(key.stringValue) <- date.datatypeValue)
case let uuid as UUID:
encoder.setters.append(Expression(key.stringValue) <- uuid.datatypeValue)
default:
let encoded = try JSONEncoder().encode(value)
let string = String(data: encoded, encoding: .utf8)
encoder.setters.append(Expression(key.stringValue) <- string)
}
try encode(value, forKey: key)
}

func encode(_ value: Int8, forKey key: Key) throws {
Expand Down

0 comments on commit abff512

Please sign in to comment.