Skip to content

Commit 12cdc95

Browse files
committed
Add basic documentation to Expression
Signed-off-by: Stephen Celis <[email protected]>
1 parent 97dca41 commit 12cdc95

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

SQLite/Expression.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,58 @@
2222
// THE SOFTWARE.
2323
//
2424

25+
/// A typed SQL expression that wraps a raw string and bindings.
2526
public struct Expression<T> {
2627

2728
public let SQL: String
29+
2830
public let bindings: [Binding?]
2931

32+
/// Builds a SQL expression with a literal string and an optional list of
33+
/// bindings.
34+
///
35+
/// :param: SQL A SQL string.
36+
///
37+
/// :param: bindings Values to be bound to the given SQL.
3038
public init(literal SQL: String = "", _ bindings: [Binding?] = []) {
3139
(self.SQL, self.bindings) = (SQL, bindings)
3240
}
3341

42+
/// Builds a SQL expression with a quoted identifier.
43+
///
44+
/// :param: identifier A SQL identifier (*e.g.*, a column name).
3445
public init(_ identifier: String) {
3546
self.init(literal: quote(identifier: identifier))
3647
}
3748

38-
public init<V>(_ expression: Expression<V>) {
39-
self.init(literal: expression.SQL, expression.bindings)
40-
}
41-
49+
/// Builds a SQL expression with the given value.
50+
///
51+
/// :param: value An encodable SQL value.
4252
public init<V: Value>(value: V?) {
4353
self.init(binding: value?.datatypeValue)
4454
}
4555

56+
/// Builds a SQL expression with the given value.
57+
///
58+
/// :param: binding A raw SQL value.
4659
private init(binding: Binding?) {
4760
self.init(literal: "?", [binding])
4861
}
4962

63+
/// Returns an ascending sort version of the expression.
5064
public var asc: Expression<()> {
5165
return Expression.join(" ", [self, Expression(literal: "ASC")])
5266
}
5367

68+
/// Returns an descending sort version of the expression.
5469
public var desc: Expression<()> {
5570
return Expression.join(" ", [self, Expression(literal: "DESC")])
5671
}
5772

73+
internal init<V>(_ expression: Expression<V>) {
74+
self.init(literal: expression.SQL, expression.bindings)
75+
}
76+
5877
internal static func join(separator: String, _ expressions: [Expressible]) -> Expression<()> {
5978
var (SQL, bindings) = ([String](), [Binding?]())
6079
for expressible in expressions {

0 commit comments

Comments
 (0)