Skip to content

Commit

Permalink
Add support for NULL/NOT NULL-based sorting (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cellane authored and tanner0101 committed Jan 11, 2019
1 parent 839cf96 commit f77bcae
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions Sources/SQL/SQLDirection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
public protocol SQLDirection: SQLSerializable {
/// Ascending order.
static var ascending: Self { get }

/// Descending order.
static var descending: Self { get }

/// Order in which NULL values come first.
static var null: Self { get }

/// Order in which NOT NULL values come first.
static var notNull: Self { get }
}

// MARK: Generic
Expand All @@ -15,23 +21,41 @@ public enum GenericSQLDirection: SQLDirection {
public static var ascending: GenericSQLDirection {
return ._ascending
}

/// See `SQLDirection`.
public static var descending: GenericSQLDirection {
return ._descending
}


/// See `SQLDirection`.
public static var null: GenericSQLDirection {
return ._null
}

/// See `SQLDirection`.
public static var notNull: GenericSQLDirection {
return ._notNull
}

/// See `SQLDirection`.
case _ascending

/// See `SQLDirection`.
case _descending


/// See `SQLDirection`.
case _null

/// See `SQLDirection`.
case _notNull

/// See `SQLSerializable`.
public func serialize(_ binds: inout [Encodable]) -> String {
switch self {
case ._ascending: return "ASC"
case ._descending: return "DESC"
case ._null: return "IS NULL"
case ._notNull: return "IS NOT NULL"
}
}
}

0 comments on commit f77bcae

Please sign in to comment.