DataLireCoder swift package
This commit is contained in:
29
Sources/DLCCommon/Extensions/SQLiteRow.swift
Normal file
29
Sources/DLCCommon/Extensions/SQLiteRow.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public extension SQLiteRow {
|
||||
func contains(_ key: CodingKey) -> Bool {
|
||||
if let index = key.intValue {
|
||||
0..<count ~= index
|
||||
} else {
|
||||
contains(key.stringValue)
|
||||
}
|
||||
}
|
||||
|
||||
subscript(key: CodingKey) -> Value? {
|
||||
get {
|
||||
if let index = key.intValue {
|
||||
self[index].value
|
||||
} else {
|
||||
self[key.stringValue]
|
||||
}
|
||||
}
|
||||
set {
|
||||
if let index = key.intValue {
|
||||
self[self[index].column] = newValue
|
||||
} else {
|
||||
self[key.stringValue] = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Sources/DLCCommon/Structures/RowCodingKey.swift
Normal file
20
Sources/DLCCommon/Structures/RowCodingKey.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
import Foundation
|
||||
|
||||
public struct RowCodingKey: CodingKey, Equatable {
|
||||
// MARK: - Properties
|
||||
|
||||
public let stringValue: String
|
||||
public let intValue: Int?
|
||||
|
||||
// MARK: - Inits
|
||||
|
||||
public init(stringValue: String) {
|
||||
self.stringValue = stringValue
|
||||
self.intValue = nil
|
||||
}
|
||||
|
||||
public init(intValue: Int) {
|
||||
self.stringValue = "Index \(intValue)"
|
||||
self.intValue = intValue
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user