|
| 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". |
1 | 9 | public struct SQLiteDialect: SQLDialect { |
2 | | - public var name: String { |
3 | | - "sqlite" |
4 | | - } |
| 10 | + public var name: String { "sqlite" } |
5 | 11 |
|
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 |
26 | 31 | } |
| 32 | + return nil |
27 | 33 | } |
28 | 34 |
|
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() { } |
52 | 36 |
|
53 | | - public var unionFeatures: SQLUnionFeatures { |
54 | | - [.union, .unionAll, .intersect, .except] |
55 | 37 | } |
56 | | - |
57 | | - public init() { } |
58 | 38 | } |
0 commit comments