DataLireCoder swift package
This commit is contained in:
6
Sources/DLCEncoder/Protocols/Container.swift
Normal file
6
Sources/DLCEncoder/Protocols/Container.swift
Normal file
@@ -0,0 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
protocol Container {
|
||||
associatedtype Encoder: Swift.Encoder
|
||||
var encoder: Encoder { get }
|
||||
}
|
||||
6
Sources/DLCEncoder/Protocols/DateEncoder.swift
Normal file
6
Sources/DLCEncoder/Protocols/DateEncoder.swift
Normal file
@@ -0,0 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
public protocol DateEncoder {
|
||||
func encode(_ date: Date, to encoder: any ValueEncoder) throws
|
||||
func encode(_ date: Date, for key: any CodingKey, to encoder: any RowEncoder) throws
|
||||
}
|
||||
8
Sources/DLCEncoder/Protocols/Encoder.swift
Normal file
8
Sources/DLCEncoder/Protocols/Encoder.swift
Normal file
@@ -0,0 +1,8 @@
|
||||
import Foundation
|
||||
|
||||
public protocol Encoder: Swift.Encoder {
|
||||
associatedtype SQLiteData
|
||||
|
||||
var dateEncoder: any DateEncoder { get }
|
||||
var sqliteData: SQLiteData { get }
|
||||
}
|
||||
15
Sources/DLCEncoder/Protocols/Flattenable.swift
Normal file
15
Sources/DLCEncoder/Protocols/Flattenable.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
import Foundation
|
||||
|
||||
protocol Flattenable {
|
||||
func flattened() -> Any?
|
||||
}
|
||||
|
||||
extension Optional: Flattenable {
|
||||
func flattened() -> Any? {
|
||||
switch self {
|
||||
case .some(let x as Flattenable): x.flattened()
|
||||
case .some(let x): x
|
||||
case .none: nil
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Sources/DLCEncoder/Protocols/RowEncoder.swift
Normal file
12
Sources/DLCEncoder/Protocols/RowEncoder.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public protocol RowEncoder: Encoder {
|
||||
var count: Int { get }
|
||||
|
||||
func set(_ value: Any, for key: CodingKey) throws
|
||||
func encodeNil(for key: CodingKey) throws
|
||||
func encodeDate(_ date: Date, for key: CodingKey) throws
|
||||
func encode<T: SQLiteRawBindable>(_ value: T, for key: CodingKey) throws
|
||||
func encoder(for key: CodingKey) throws -> any Encoder
|
||||
}
|
||||
8
Sources/DLCEncoder/Protocols/ValueEncoder.swift
Normal file
8
Sources/DLCEncoder/Protocols/ValueEncoder.swift
Normal file
@@ -0,0 +1,8 @@
|
||||
import Foundation
|
||||
import DataLiteCore
|
||||
|
||||
public protocol ValueEncoder: Encoder {
|
||||
func encodeNil() throws
|
||||
func encodeDate(_ date: Date) throws
|
||||
func encode<T: SQLiteRawBindable>(_ value: T) throws
|
||||
}
|
||||
Reference in New Issue
Block a user