diff --git a/Sources/StORM/StORM.swift b/Sources/StORM/StORM.swift index 8d001d7..877baae 100644 --- a/Sources/StORM/StORM.swift +++ b/Sources/StORM/StORM.swift @@ -6,11 +6,36 @@ // // -class StORM { - var cursor = StORMCursor() - var error = StORMError() - var results = StORMResultSet() - var connection = StORMConnect() +open class StORM { + // open var connection = StORMConnect() // covariant? + // open var cursor = StORMCursor() + open var results = StORMResultSet() + open var error = StORMError() + + public init() {} + + // introspection of structure + public func cols() -> [String:Any] { + var c = [String:Any]() + + let mirror = Mirror(reflecting: self) + for child in mirror.children { + guard let key = child.label else { + continue + } + c[key] = type(of:child.value) + } + return c + } + + + public func firstAsKey() -> (String, Any) { + let mirror = Mirror(reflecting: self) + for case let (label?, value) in mirror.children { + return (label, value) + } + return ("id", "unknown") + } } diff --git a/Sources/StORM/StORMProtocol.swift b/Sources/StORM/StORMProtocol.swift new file mode 100644 index 0000000..07718b5 --- /dev/null +++ b/Sources/StORM/StORMProtocol.swift @@ -0,0 +1,9 @@ +// +// StORMProtocol.swift +// StORM +// +// Created by Jonathan Guthrie on 2016-09-30. +// +// + +import Foundation