PostgresValue
public struct PostgresValue : PostgresValueConvertible, Equatable, CustomStringConvertible
A value to be sent to or returned from the Postgres server.
PostgresClientKit extends standard Swift types to conform to the PostgresValueConvertible
protocol, making it easy to convert instances of those types to PostgresValue. For example:
// Convert String to PostgresValue.
let greeting = "Hello, world!"
let greetingValue = greeting.postgresValue
// Convert Double to PostgresValue.
let pi = 3.14
let piValue = pi.postgresValue
// Convert an optional Int to PostgresValue.
let score: Int? = nil
let scoreValue = score.postgresValue
Use PostgresValue methods to convert PostgresValue instances back to standard Swift types.
These methods throw errors if the conversion fails.
try greetingValue.string() // "Hello, world!"
try greetingValue.int() // throws PostgresError.valueConversionError
try piValue.double() // 3.14
try piValue.string() // "3.14"
try scoreValue.optionalInt() // nil
try scoreValue.int() // throws PostgresError.valueIsNil
-
Creates a
PostgresValuefrom the raw value used in the Postgres network protocol.Declaration
Swift
public init(_ rawValue: String?)Parameters
rawValuethe raw value, or
nilto represent a SQLNULLvalue -
The raw value used in the Postgres network protocol, or
nilto represent a SQLNULLvalue.Declaration
Swift
public let rawValue: String? -
Whether this
PostgresValuerepresents a SQLNULLvalue.Declaration
Swift
public var isNull: Bool { get }
-
Converts this
PostgresValueto aString.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func string() throws -> StringReturn Value
the
String -
Converts this
PostgresValueto an optionalString.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalString() throws -> String?Return Value
the optional
String
-
Converts this
PostgresValueto anInt.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func int() throws -> IntReturn Value
the
Int -
Converts this
PostgresValueto an optionalInt.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalInt() throws -> Int?Return Value
the optional
Int
-
Converts this
PostgresValueto aDouble.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func double() throws -> DoubleReturn Value
the
Double -
Converts this
PostgresValueto an optionalDouble.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalDouble() throws -> Double?Return Value
the optional
Double
-
Converts this
PostgresValueto aDecimal.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func decimal() throws -> DecimalReturn Value
the
Decimal -
Converts this
PostgresValueto an optionalDecimal.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalDecimal() throws -> Decimal?Return Value
the optional
Decimal
-
Converts this
PostgresValueto aBool.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func bool() throws -> BoolReturn Value
the
Bool -
Converts this
PostgresValueto an optionalBoolThrows
PostgresErrorif the conversion failsDeclaration
Swift
func optionalBool() throws -> Bool?Return Value
the optional
Bool
-
Converts this
PostgresValueto aPostgresTimestampWithTimeZone.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func timestampWithTimeZone() throws -> PostgresTimestampWithTimeZoneReturn Value
-
Converts this
PostgresValueto an optionalPostgresTimestampWithTimeZone.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalTimestampWithTimeZone() throws -> PostgresTimestampWithTimeZone?Return Value
the optional
PostgresTimestampWithTimeZone
-
Converts this
PostgresValueto aPostgresTimestamp.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func timestamp() throws -> PostgresTimestampReturn Value
-
Converts this
PostgresValueto an optionalPostgresTimestamp.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalTimestamp() throws -> PostgresTimestamp?Return Value
the optional
PostgresTimestamp
-
Converts this
PostgresValueto aPostgresDate.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func date() throws -> PostgresDateReturn Value
the
PostgresDate -
Converts this
PostgresValueto an optionalPostgresDate.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalDate() throws -> PostgresDate?Return Value
the optional
PostgresDate
-
Converts this
PostgresValueto aPostgresTime.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func time() throws -> PostgresTimeReturn Value
the
PostgresTime -
Converts this
PostgresValueto an optionalPostgresTime.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalTime() throws -> PostgresTime?Return Value
the optional
PostgresTime
-
Converts this
PostgresValueto aPostgresTimeWithTimeZone.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func timeWithTimeZone() throws -> PostgresTimeWithTimeZoneReturn Value
-
Converts this
PostgresValueto an optionalPostgresTimeWithTimeZone.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalTimeWithTimeZone() throws -> PostgresTimeWithTimeZone?Return Value
the optional
PostgresTimeWithTimeZone
-
Converts this
PostgresValueto aPostgresByteA.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func byteA() throws -> PostgresByteAReturn Value
the
PostgresByteA -
Converts this
PostgresValueto an optionalPostgresByteA.Throws
PostgresErrorif the conversion failsDeclaration
Swift
func optionalByteA() throws -> PostgresByteA?Return Value
the optional
PostgresByteA
-
The
PostgresValueitself.Declaration
Swift
var postgresValue: PostgresValue { get }
-
True if
lhs.rawValue == rhs.rawValue.Declaration
Swift
static func == (lhs: PostgresValue, rhs: PostgresValue) -> Bool
-
A short string that describes this
PostgresValue.Declaration
Swift
var description: String { get }