Skip to content

Commit 6b299ba

Browse files
committed
Do a mostly visual update to SQLiteDialect, removing quite a lot of confusing whitespace and simplifying most of the content. Adds a customDataType(for:) override to handling requests for bigint types and switches from plain ? for placeholders to SQLite's numbered ?NNNN representation per SQLite docs recommendation.
1 parent 89cf963 commit 6b299ba

File tree

1 file changed

+30
-50
lines changed

1 file changed

+30
-50
lines changed
Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,38 @@
1+
import SQLKit
2+
3+
/// The ``SQLDialect`` defintions for SQLite.
4+
///
5+
/// - Note: There is only ever one SQLite library in use by SQLiteNIO in any given process (even if there are
6+
/// other versions of the library being used by other things). As such, there is no need for the dialect to
7+
/// concern itself with what version the connection using it "connected" to - it can always just look up the
8+
/// global "runtime version".
19
public struct SQLiteDialect: SQLDialect {
2-
public var name: String {
3-
"sqlite"
4-
}
10+
public var name: String { "sqlite" }
511

6-
public var identifierQuote: SQLExpression {
7-
return SQLRaw("\"")
8-
}
9-
10-
public var literalStringQuote: SQLExpression {
11-
return SQLRaw("'")
12-
}
13-
14-
public var autoIncrementClause: SQLExpression {
15-
return SQLRaw("AUTOINCREMENT")
16-
}
17-
18-
public func bindPlaceholder(at position: Int) -> SQLExpression {
19-
return SQLRaw("?")
20-
}
21-
22-
public func literalBoolean(_ value: Bool) -> SQLExpression {
23-
switch value {
24-
case true: return SQLRaw("TRUE")
25-
case false: return SQLRaw("FALSE")
12+
public var identifierQuote: SQLExpression { SQLRaw("\"") }
13+
public var literalStringQuote: SQLExpression { SQLRaw("'") }
14+
public func bindPlaceholder(at position: Int) -> SQLExpression { SQLRaw("?\(position)") }
15+
public func literalBoolean(_ value: Bool) -> SQLExpression { SQLRaw(value ? "TRUE" : "FALSE") }
16+
public var literalDefault: SQLExpression { SQLLiteral.null }
17+
18+
public var supportsAutoIncrement: Bool { false }
19+
public var autoIncrementClause: SQLExpression { SQLRaw("AUTOINCREMENT") }
20+
21+
public var enumSyntax: SQLEnumSyntax { .unsupported }
22+
public var triggerSyntax: SQLTriggerSyntax { .init(create: [.supportsBody, .supportsCondition]) }
23+
public var alterTableSyntax: SQLAlterTableSyntax { .init(allowsBatch: false) }
24+
public var unionFeatures: SQLUnionFeatures { [.union, .unionAll, .intersect, .except] }
25+
26+
public func customDataType(for dataType: SQLDataType) -> SQLExpression? {
27+
if case .bigint = dataType {
28+
// Translate requests for bigint to requests for SQLite's plain integer type. This yields the autoincrement
29+
// primary key behavior when a 64-bit integer is requested from a higher layer.
30+
return SQLDataType.int
2631
}
32+
return nil
2733
}
2834

29-
public var literalDefault: SQLExpression {
30-
return SQLLiteral.null
31-
}
32-
33-
public var enumSyntax: SQLEnumSyntax {
34-
.unsupported
35-
}
36-
37-
public var supportsAutoIncrement: Bool {
38-
false
39-
}
40-
41-
public var alterTableSyntax: SQLAlterTableSyntax {
42-
.init(
43-
alterColumnDefinitionClause: nil,
44-
alterColumnDefinitionTypeKeyword: nil,
45-
allowsBatch: false
46-
)
47-
}
48-
49-
public var triggerSyntax: SQLTriggerSyntax {
50-
return .init(create: [.supportsBody, .supportsCondition])
51-
}
35+
public init() { }
5236

53-
public var unionFeatures: SQLUnionFeatures {
54-
[.union, .unionAll, .intersect, .except]
5537
}
56-
57-
public init() { }
5838
}

0 commit comments

Comments
 (0)