@@ -9,19 +9,19 @@ public struct MySQLDialect: SQLDialect {
9
9
" mysql "
10
10
}
11
11
12
- public var identifierQuote : SQLExpression {
12
+ public var identifierQuote : any SQLExpression {
13
13
return SQLRaw ( " ` " )
14
14
}
15
15
16
- public var literalStringQuote : SQLExpression {
16
+ public var literalStringQuote : any SQLExpression {
17
17
return SQLRaw ( " ' " )
18
18
}
19
19
20
- public func bindPlaceholder( at position: Int ) -> SQLExpression {
20
+ public func bindPlaceholder( at position: Int ) -> any SQLExpression {
21
21
return SQLRaw ( " ? " )
22
22
}
23
23
24
- public func literalBoolean( _ value: Bool ) -> SQLExpression {
24
+ public func literalBoolean( _ value: Bool ) -> any SQLExpression {
25
25
switch value {
26
26
case false :
27
27
return SQLRaw ( " 0 " )
@@ -30,7 +30,7 @@ public struct MySQLDialect: SQLDialect {
30
30
}
31
31
}
32
32
33
- public var autoIncrementClause : SQLExpression {
33
+ public var autoIncrementClause : any SQLExpression {
34
34
return SQLRaw ( " AUTO_INCREMENT " )
35
35
}
36
36
@@ -42,7 +42,7 @@ public struct MySQLDialect: SQLDialect {
42
42
. inline
43
43
}
44
44
45
- public func customDataType( for dataType: SQLDataType ) -> SQLExpression ? {
45
+ public func customDataType( for dataType: SQLDataType ) -> ( any SQLExpression ) ? {
46
46
switch dataType {
47
47
case . text:
48
48
return SQLRaw ( " VARCHAR(255) " )
@@ -58,7 +58,7 @@ public struct MySQLDialect: SQLDialect {
58
58
)
59
59
}
60
60
61
- public func normalizeSQLConstraint( identifier: SQLExpression ) -> SQLExpression {
61
+ public func normalizeSQLConstraint( identifier: any SQLExpression ) -> any SQLExpression {
62
62
if let sqlIdentifier = identifier as? SQLIdentifier {
63
63
return SQLIdentifier ( Insecure . SHA1. hash ( data: Data ( sqlIdentifier. string. utf8) ) . hexRepresentation)
64
64
} else {
@@ -78,13 +78,26 @@ public struct MySQLDialect: SQLDialect {
78
78
[ . union, . unionAll, . explicitDistinct, . parenthesizedSubqueries]
79
79
}
80
80
81
- public var sharedSelectLockExpression : SQLExpression ? {
81
+ public var sharedSelectLockExpression : ( any SQLExpression ) ? {
82
82
SQLRaw ( " LOCK IN SHARE MODE " )
83
83
}
84
84
85
- public var exclusiveSelectLockExpression : SQLExpression ? {
85
+ public var exclusiveSelectLockExpression : ( any SQLExpression ) ? {
86
86
SQLRaw ( " FOR UPDATE " )
87
87
}
88
+
89
+ public func nestedSubpathExpression( in column: any SQLExpression , for path: [ String ] ) -> ( any SQLExpression ) ? {
90
+ guard !path. isEmpty else { return nil }
91
+
92
+ // N.B.: While MySQL has had the `->` and `->>` operators since 5.7.13, there are still implementations with
93
+ // which they do not work properly (most notably AWS's Aurora 2.x), so we use the legacy functions instead.
94
+ return SQLFunction ( " json_unquote " , args:
95
+ SQLFunction ( " json_extract " , args: [
96
+ column,
97
+ SQLLiteral . string ( " $. \( path. joined ( separator: " . " ) ) " )
98
+ ]
99
+ ) )
100
+ }
88
101
}
89
102
90
103
fileprivate let hexTable : [ UInt8 ] = [ 0x30 , 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39 , 0x61 , 0x62 , 0x63 , 0x64 , 0x65 , 0x66 ]
0 commit comments