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
PostgresValue
from the raw value used in the Postgres network protocol.Declaration
Swift
public init(_ rawValue: String?)
Parameters
rawValue
the raw value, or
nil
to represent a SQLNULL
value -
The raw value used in the Postgres network protocol, or
nil
to represent a SQLNULL
value.Declaration
Swift
public let rawValue: String?
-
Whether this
PostgresValue
represents a SQLNULL
value.Declaration
Swift
public var isNull: Bool { get }
-
Converts this
PostgresValue
to aString
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func string() throws -> String
Return Value
the
String
-
Converts this
PostgresValue
to an optionalString
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalString() throws -> String?
Return Value
the optional
String
-
Converts this
PostgresValue
to anInt
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func int() throws -> Int
Return Value
the
Int
-
Converts this
PostgresValue
to an optionalInt
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalInt() throws -> Int?
Return Value
the optional
Int
-
Converts this
PostgresValue
to aDouble
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func double() throws -> Double
Return Value
the
Double
-
Converts this
PostgresValue
to an optionalDouble
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalDouble() throws -> Double?
Return Value
the optional
Double
-
Converts this
PostgresValue
to aDecimal
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func decimal() throws -> Decimal
Return Value
the
Decimal
-
Converts this
PostgresValue
to an optionalDecimal
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalDecimal() throws -> Decimal?
Return Value
the optional
Decimal
-
Converts this
PostgresValue
to aBool
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func bool() throws -> Bool
Return Value
the
Bool
-
Converts this
PostgresValue
to an optionalBool
Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalBool() throws -> Bool?
Return Value
the optional
Bool
-
Converts this
PostgresValue
to aPostgresTimestampWithTimeZone
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func timestampWithTimeZone() throws -> PostgresTimestampWithTimeZone
Return Value
-
Converts this
PostgresValue
to an optionalPostgresTimestampWithTimeZone
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalTimestampWithTimeZone() throws -> PostgresTimestampWithTimeZone?
Return Value
the optional
PostgresTimestampWithTimeZone
-
Converts this
PostgresValue
to aPostgresTimestamp
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func timestamp() throws -> PostgresTimestamp
Return Value
-
Converts this
PostgresValue
to an optionalPostgresTimestamp
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalTimestamp() throws -> PostgresTimestamp?
Return Value
the optional
PostgresTimestamp
-
Converts this
PostgresValue
to aPostgresDate
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func date() throws -> PostgresDate
Return Value
the
PostgresDate
-
Converts this
PostgresValue
to an optionalPostgresDate
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalDate() throws -> PostgresDate?
Return Value
the optional
PostgresDate
-
Converts this
PostgresValue
to aPostgresTime
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func time() throws -> PostgresTime
Return Value
the
PostgresTime
-
Converts this
PostgresValue
to an optionalPostgresTime
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalTime() throws -> PostgresTime?
Return Value
the optional
PostgresTime
-
Converts this
PostgresValue
to aPostgresTimeWithTimeZone
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func timeWithTimeZone() throws -> PostgresTimeWithTimeZone
Return Value
-
Converts this
PostgresValue
to an optionalPostgresTimeWithTimeZone
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalTimeWithTimeZone() throws -> PostgresTimeWithTimeZone?
Return Value
the optional
PostgresTimeWithTimeZone
-
Converts this
PostgresValue
to aPostgresByteA
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func byteA() throws -> PostgresByteA
Return Value
the
PostgresByteA
-
Converts this
PostgresValue
to an optionalPostgresByteA
.Throws
PostgresError
if the conversion failsDeclaration
Swift
func optionalByteA() throws -> PostgresByteA?
Return Value
the optional
PostgresByteA
-
The
PostgresValue
itself.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 }