Skip to content

Commit 2d07e03

Browse files
authored
Remove #sql literal requirement (#122)
It's overly restrictive. While passing a query fragment directly is equivalent to `SQLQueryExpression(fragment)`, it doesn't seem worth a hard error. Alternately we could make it a warning with a fix-it that swaps `#sql` for `SQLQueryExpression`, but not sure it's worth the distinction?
1 parent f69749f commit 2d07e03

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

Sources/StructuredQueriesCore/QueryFragment.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
/// You will typically create instances of this type using string literals, where bindings are
44
/// directly interpolated into the string. This most commonly occurs when using the `#sql` macro,
55
/// which takes values of this type.
6+
///
7+
/// > Tip: The `#sql` macro performs basic linting and validation of a SQL string literal. Prefer it
8+
/// > for creating `QueryFragment`s where possible.
69
public struct QueryFragment: Hashable, Sendable {
710
/// A segment of a query fragment.
811
public enum Segment: Hashable, Sendable {

Sources/StructuredQueriesMacros/SQLMacro.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,6 @@ public enum SQLMacro: ExpressionMacro {
195195
)
196196
)
197197
}
198-
} else {
199-
context.diagnose(
200-
Diagnostic(
201-
node: argument,
202-
message: MacroExpansionErrorMessage(
203-
"""
204-
'#sql' requires a query literal.
205-
"""
206-
)
207-
)
208-
)
209198
}
210199
return "\(moduleName).SQLQueryExpression(\(argument))"
211200
}

Sources/StructuredQueriesMacros/TableMacro.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ extension TableMacro: ExtensionMacro {
570570
var letSchemaName: DeclSyntax?
571571
if let schemaName {
572572
letSchemaName = """
573+
573574
public static let schemaName: Swift.String? = \(schemaName)
574575
"""
575576
}
@@ -1038,7 +1039,7 @@ extension TableMacro: MemberMacro {
10381039
[\(writableColumns.map { "QueryValue.columns.\($0)" as ExprSyntax }, separator: ", ")]
10391040
}
10401041
public var queryFragment: QueryFragment {
1041-
"\(selectedColumns.map { #"\(self.\#($0))"# as ExprSyntax }, separator: ", ")"
1042+
"\(raw: selectedColumns.map { #"\(self.\#($0))"# }.joined(separator: ", "))"
10421043
}
10431044
}
10441045
""",

0 commit comments

Comments
 (0)