0001    // Value.swift
0002    //
0003    // The MIT License (MIT)
0004    //
0005    // Copyright (c) 2015 Formbound
0006    //
0007    // Permission is hereby granted, free of charge, to any person obtaining a copy
0008    // of this software and associated documentation files (the "Software"), to deal
0009    // in the Software without restriction, including without limitation the rights
0010    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0011    // copies of the Software, and to permit persons to whom the Software is
0012    // furnished to do so, subject to the following conditions:
0013    //
0014    // The above copyright notice and this permission notice shall be included in all
0015    // copies or substantial portions of the Software.
0016    //
0017    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0018    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0019    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0020    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0021    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0022    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0023    // SOFTWARE.
0024    
0025    @_exported import Data
0026    
0027    public struct ValueConversionError: ErrorType {
0028        let description: String
0029    }
0030    
0031    public enum Value
Value.swift:37
    var SQLValue: Value { get }
Value.swift:62
    public var SQLValue: Value {
Value.swift:75
    public var SQLValue: Value {
Value.swift:88
    public var SQLValue: Value {
Value.swift:101
    public var SQLValue: Value {
Value.swift:111
    public var SQLValue: Value {
{ 0032 case Text
Value.swift:48
        case .Text(let text):
Value.swift:112
        return .Text(self)
(String) 0033 case Binary(Data) 0034 } 0035 0036 public protocol ValueConvertible
Row.swift:107
    public func value<T: ValueConvertible>(fieldName: String) throws -> T? {
Row.swift:115
    public func value<T: ValueConvertible>(fieldName: String) throws -> T {
Row.swift:134
    public func value<T: ValueConvertible, F: ModelFieldset>(field: F) throws -> T? {
Row.swift:138
    public func value<T: ValueConvertible, F: ModelFieldset>(field: F) throws -> T {
Statement.swift:27
    public var parameters: [ValueConvertible?]
Statement.swift:38
    public init(_ string: String, parameters: [ValueConvertible?] = []) {
Statement.swift:43
    public init(components: [String], parameters: [ValueConvertible?] = []) {
Value.swift:42
public extension ValueConvertible {
Value.swift:54
extension Int: ValueConvertible {
Value.swift:67
extension UInt: ValueConvertible {
Value.swift:80
extension Float: ValueConvertible {
Value.swift:93
extension Double: ValueConvertible {
Value.swift:106
extension String: ValueConvertible {
Condition.swift:27
        case Value(ValueConvertible?)
Condition.swift:40
    case In(String, [ValueConvertible?])
Condition.swift:41
    case NotIn(String, [ValueConvertible?])
Model.swift:55
    public func containedIn(values: [ValueConvertible?]) -> Condition {
Model.swift:59
    public func containedIn(values: ValueConvertible?...) -> Condition {
Model.swift:63
    public func notContainedIn(values: [ValueConvertible?]) -> Condition {
Model.swift:67
    public func notContainedIn(values: ValueConvertible?...) -> Condition {
Model.swift:72
public func == <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {
Model.swift:80
public func > <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {
Model.swift:89
public func >= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {
Model.swift:98
public func < <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {
Model.swift:107
public func <= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {
Model.swift:130
    public static func insert(valuesByFieldName: [Field: ValueConvertible?]) -> Insert<Self> {
Query.swift:108
    internal var valuesByFieldName: [M.Field: ValueConvertible?] = [:]
Query.swift:110
    public func set(field: M.Field, value: ValueConvertible?) -> Insert {
Query.swift:116
    public init(_ valuesByFieldName: [M.Field: ValueConvertible?]) {
{ 0037 var SQLValue
Value.swift:45
        switch self.SQLValue {
: Value { get } 0038 0039 init(rawSQLValue data: Data) throws 0040 } 0041 0042 public extension ValueConvertible { 0043 0044 public var SQLString: String? { 0045 switch self.SQLValue { 0046 case .Binary(let data): 0047 return try? String(data: data) 0048 case .Text(let text): 0049 return text 0050 } 0051 } 0052 } 0053 0054 extension Int: ValueConvertible { 0055 public init(rawSQLValue data: Data) throws { 0056 guard let value = Int(try String(data: data)) else { 0057 throw ValueConversionError(description: "Failed to convert data to Int") 0058 } 0059 self = value 0060 } 0061 0062 public var SQLValue: Value { 0063 return .Text(String(self)) 0064 } 0065 } 0066 0067 extension UInt: ValueConvertible { 0068 public init(rawSQLValue data: Data) throws { 0069 guard let value = UInt(try String(data: data)) else { 0070 throw ValueConversionError(description: "Failed to convert data to UInt") 0071 } 0072 self = value 0073 } 0074 0075 public var SQLValue: Value { 0076 return .Text(String(self)) 0077 } 0078 } 0079 0080 extension Float: ValueConvertible { 0081 public init(rawSQLValue data: Data) throws { 0082 guard let value = Float(try String(data: data)) else { 0083 throw ValueConversionError(description: "Failed to convert data to Float") 0084 } 0085 self = value 0086 } 0087 0088 public var SQLValue: Value { 0089 return .Text(String(self)) 0090 } 0091 } 0092 0093 extension Double: ValueConvertible { 0094 public init(rawSQLValue data: Data) throws { 0095 guard let value = Double(try String(data: data)) else { 0096 throw ValueConversionError(description: "Failed to convert data to Double") 0097 } 0098 self = value 0099 } 0100 0101 public var SQLValue: Value { 0102 return .Text(String(self)) 0103 } 0104 } 0105 0106 extension String: ValueConvertible { 0107 public init(rawSQLValue data: Data) throws { 0108 try self.init(data: data) 0109 } 0110 0111 public var SQLValue: Value { 0112 return .Text(self) 0113 } 0114 } 0115 0116 extension Data: ValueConvertible { 0117 public init(rawSQLValue data: Data) throws { 0118 self = data 0119 } 0120 0121 public var SQLValue: Value { 0122 return .Binary(self) 0123 } 0124 } 0125