-
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathSQLDialectDescriptor.swift
More file actions
76 lines (68 loc) · 2.79 KB
/
SQLDialectDescriptor.swift
File metadata and controls
76 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Foundation
public struct CompletionEntry: Sendable {
public let label: String
public let insertText: String
public init(label: String, insertText: String) {
self.label = label
self.insertText = insertText
}
}
public struct SQLDialectDescriptor: Sendable {
public let identifierQuote: String
public let keywords: Set<String>
public let functions: Set<String>
public let dataTypes: Set<String>
public let tableOptions: [String]
// Filter dialect
public let regexSyntax: RegexSyntax
public let booleanLiteralStyle: BooleanLiteralStyle
public let likeEscapeStyle: LikeEscapeStyle
public let paginationStyle: PaginationStyle
public let offsetFetchOrderBy: String
public let requiresBackslashEscaping: Bool
public enum RegexSyntax: String, Sendable {
case regexp // MySQL: column REGEXP 'pattern'
case tilde // PostgreSQL: column ~ 'pattern'
case regexpMatches // DuckDB: regexp_matches(column, 'pattern')
case match // ClickHouse: match(column, 'pattern')
case regexpLike // Oracle: REGEXP_LIKE(column, 'pattern')
case unsupported // SQLite, MSSQL, MongoDB, Redis
}
public enum BooleanLiteralStyle: String, Sendable {
case truefalse // PostgreSQL, DuckDB: TRUE/FALSE
case numeric // MySQL, SQLite, etc: 1/0
}
public enum LikeEscapeStyle: String, Sendable {
case implicit // MySQL: backslash is default escape, no ESCAPE clause needed
case explicit // PostgreSQL, SQLite, etc: need ESCAPE '\' clause
}
public enum PaginationStyle: String, Sendable {
case limit // MySQL, PostgreSQL, SQLite, etc: LIMIT n
case offsetFetch // Oracle, MSSQL: OFFSET n ROWS FETCH NEXT m ROWS ONLY
}
public init(
identifierQuote: String,
keywords: Set<String>,
functions: Set<String>,
dataTypes: Set<String>,
tableOptions: [String] = [],
regexSyntax: RegexSyntax = .unsupported,
booleanLiteralStyle: BooleanLiteralStyle = .numeric,
likeEscapeStyle: LikeEscapeStyle = .explicit,
paginationStyle: PaginationStyle = .limit,
offsetFetchOrderBy: String = "ORDER BY (SELECT NULL)",
requiresBackslashEscaping: Bool = false
) {
self.identifierQuote = identifierQuote
self.keywords = keywords
self.functions = functions
self.dataTypes = dataTypes
self.tableOptions = tableOptions
self.regexSyntax = regexSyntax
self.booleanLiteralStyle = booleanLiteralStyle
self.likeEscapeStyle = likeEscapeStyle
self.paginationStyle = paginationStyle
self.offsetFetchOrderBy = offsetFetchOrderBy
self.requiresBackslashEscaping = requiresBackslashEscaping
}
}