adding start of introspection

This commit is contained in:
Jonathan Guthrie 2016-10-05 10:31:08 -04:00
parent 2a0cc5e27b
commit 0e7288c2ba
2 changed files with 39 additions and 5 deletions

View File

@ -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")
}
}

View File

@ -0,0 +1,9 @@
//
// StORMProtocol.swift
// StORM
//
// Created by Jonathan Guthrie on 2016-09-30.
//
//
import Foundation