Skip to content

Use StructuredQueriesCore module name in macro expansions. #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Sources/StructuredQueriesCore/PrimaryKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public protocol PrimaryKeyedTable: Table where TableColumns: PrimaryKeyedTableDe
// A type representing a draft to be saved to a table with a primary key.
public protocol TableDraft: Table {
/// A type that represents the table with a primary key.
associatedtype PrimaryTable: StructuredQueriesCore.PrimaryKeyedTable
where PrimaryTable.Draft == Self
associatedtype PrimaryTable: PrimaryKeyedTable where PrimaryTable.Draft == Self

/// Creates a draft from a primary keyed table.
init(_ primaryTable: PrimaryTable)
Expand Down
2 changes: 1 addition & 1 deletion Sources/StructuredQueriesCore/Seeds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public struct Seeds: Sequence {

return insertBatch(firstType)
} else {
func insertBatch<T: StructuredQueriesCore.Table>(_: T.Type) -> SQLQueryExpression<Void> {
func insertBatch<T: Table>(_: T.Type) -> SQLQueryExpression<Void> {
let batch = Array(seeds.lazy.prefix { $0 is T }.compactMap { $0 as? T })
defer { seeds.removeFirst(batch.count) }
return SQLQueryExpression(T.insert(batch))
Expand Down
2 changes: 1 addition & 1 deletion Sources/StructuredQueriesMacros/BindMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public enum BindMacro: ExpressionMacro {
) -> ExprSyntax {
guard let argument = node.arguments.first?.expression else { fatalError() }
let `as` = node.arguments.dropFirst().first
return "StructuredQueries.BindQueryExpression(\(argument)\(raw: `as`.map { ", \($0)" } ?? ""))"
return "\(moduleName).BindQueryExpression(\(argument)\(raw: `as`.map { ", \($0)" } ?? ""))"
}
}
2 changes: 1 addition & 1 deletion Sources/StructuredQueriesMacros/Internal/Support.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftSyntax
import SwiftSyntaxBuilder

let moduleName: TokenSyntax = "StructuredQueries"
let moduleName: TokenSyntax = "StructuredQueriesCore"

extension String {
func trimmingBackticks() -> String {
Expand Down
2 changes: 1 addition & 1 deletion Sources/StructuredQueriesMacros/SQLMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ public enum SQLMacro: ExpressionMacro {
)
)
}
return "StructuredQueries.SQLQueryExpression(\(argument))"
return "\(moduleName).SQLQueryExpression(\(argument))"
}
}
4 changes: 2 additions & 2 deletions Tests/StructuredQueriesMacrosTests/BindMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension SnapshotTests {
"""#
} expansion: {
#"""
\(date) < StructuredQueries.BindQueryExpression(Date())
\(date) < StructuredQueriesCore.BindQueryExpression(Date())
"""#
}
}
Expand All @@ -24,7 +24,7 @@ extension SnapshotTests {
"""#
} expansion: {
#"""
\(date) < StructuredQueries.BindQueryExpression(Date(), as: Date.ISO8601Representation.self)
\(date) < StructuredQueriesCore.BindQueryExpression(Date(), as: Date.ISO8601Representation.self)
"""#
}
}
Expand Down
32 changes: 16 additions & 16 deletions Tests/StructuredQueriesMacrosTests/SQLMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression("CURRENT_TIMESTAMP")
StructuredQueriesCore.SQLQueryExpression("CURRENT_TIMESTAMP")
"""
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression("'('")
StructuredQueriesCore.SQLQueryExpression("'('")
"""
}
assertMacro {
Expand All @@ -99,7 +99,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression("[it's fine]")
StructuredQueriesCore.SQLQueryExpression("[it's fine]")
"""
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression(#""text" = 'hello?'"#)
StructuredQueriesCore.SQLQueryExpression(#""text" = 'hello?'"#)
"""
}
assertMacro {
Expand All @@ -178,7 +178,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression(#""text" = 'hello?1'"#)
StructuredQueriesCore.SQLQueryExpression(#""text" = 'hello?1'"#)
"""
}
assertMacro {
Expand All @@ -187,7 +187,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression(#""text" = 'hello:hi'"#)
StructuredQueriesCore.SQLQueryExpression(#""text" = 'hello:hi'"#)
"""
}
assertMacro {
Expand All @@ -196,7 +196,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression(#""text" = 'hello@hi'"#)
StructuredQueriesCore.SQLQueryExpression(#""text" = 'hello@hi'"#)
"""
}
assertMacro {
Expand All @@ -205,7 +205,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression(#""text" = 'hello$hi'"#)
StructuredQueriesCore.SQLQueryExpression(#""text" = 'hello$hi'"#)
"""
}
}
Expand All @@ -228,7 +228,7 @@ extension SnapshotTests {
"""#
} expansion: {
#"""
StructuredQueries.SQLQueryExpression("'\(raw: 42)'")
StructuredQueriesCore.SQLQueryExpression("'\(raw: 42)'")
"""#
}
}
Expand All @@ -240,7 +240,7 @@ extension SnapshotTests {
"""#
} expansion: {
#"""
StructuredQueries.SQLQueryExpression("'\(raw: 42)'")
StructuredQueriesCore.SQLQueryExpression("'\(raw: 42)'")
"""#
}
}
Expand All @@ -252,7 +252,7 @@ extension SnapshotTests {
"""#
} expansion: {
#"""
StructuredQueries.SQLQueryExpression("\($0.dueDate) < date('now', '-\(raw: monthsAgo) months')")
StructuredQueriesCore.SQLQueryExpression("\($0.dueDate) < date('now', '-\(raw: monthsAgo) months')")
"""#
}
}
Expand All @@ -264,7 +264,7 @@ extension SnapshotTests {
"""#
} expansion: {
"""
StructuredQueries.SQLQueryExpression("''")
StructuredQueriesCore.SQLQueryExpression("''")
"""
}
assertMacro {
Expand All @@ -277,7 +277,7 @@ extension SnapshotTests {
"""#
} expansion: {
#"""
StructuredQueries.SQLQueryExpression(
StructuredQueriesCore.SQLQueryExpression(
"""
""
""")
Expand All @@ -289,7 +289,7 @@ extension SnapshotTests {
"""#
} expansion: {
"""
StructuredQueries.SQLQueryExpression("[]")
StructuredQueriesCore.SQLQueryExpression("[]")
"""
}
}
Expand All @@ -305,7 +305,7 @@ extension SnapshotTests {
"""#
} expansion: {
#"""
StructuredQueries.SQLQueryExpression(
StructuredQueriesCore.SQLQueryExpression(
"""
SELECT 1 AS "a ""real"" one"
""")
Expand Down Expand Up @@ -356,7 +356,7 @@ extension SnapshotTests {
"""
} expansion: {
"""
StructuredQueries.SQLQueryExpression("json_extract(notes, '$.body')")
StructuredQueriesCore.SQLQueryExpression("json_extract(notes, '$.body')")
"""
}
}
Expand Down
44 changes: 22 additions & 22 deletions Tests/StructuredQueriesMacrosTests/SelectionMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ extension SnapshotTests {
let team: Team
}

extension PlayerAndTeam: StructuredQueries.QueryRepresentable {
public struct Columns: StructuredQueries.QueryExpression {
extension PlayerAndTeam: StructuredQueriesCore.QueryRepresentable {
public struct Columns: StructuredQueriesCore.QueryExpression {
public typealias QueryValue = PlayerAndTeam
public let queryFragment: StructuredQueries.QueryFragment
public let queryFragment: StructuredQueriesCore.QueryFragment
public init(
player: some StructuredQueries.QueryExpression<Player>,
team: some StructuredQueries.QueryExpression<Team>
player: some StructuredQueriesCore.QueryExpression<Player>,
team: some StructuredQueriesCore.QueryExpression<Team>
) {
self.queryFragment = """
\(player.queryFragment) AS "player", \(team.queryFragment) AS "team"
"""
}
}
public init(decoder: inout some StructuredQueries.QueryDecoder) throws {
public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws {
let player = try decoder.decode(Player.self)
let team = try decoder.decode(Team.self)
guard let player else {
Expand Down Expand Up @@ -82,20 +82,20 @@ extension SnapshotTests {
var listTitle: String?
}

extension ReminderTitleAndListTitle: StructuredQueries.QueryRepresentable {
public struct Columns: StructuredQueries.QueryExpression {
extension ReminderTitleAndListTitle: StructuredQueriesCore.QueryRepresentable {
public struct Columns: StructuredQueriesCore.QueryExpression {
public typealias QueryValue = ReminderTitleAndListTitle
public let queryFragment: StructuredQueries.QueryFragment
public let queryFragment: StructuredQueriesCore.QueryFragment
public init(
reminderTitle: some StructuredQueries.QueryExpression<String>,
listTitle: some StructuredQueries.QueryExpression<String?>
reminderTitle: some StructuredQueriesCore.QueryExpression<String>,
listTitle: some StructuredQueriesCore.QueryExpression<String?>
) {
self.queryFragment = """
\(reminderTitle.queryFragment) AS "reminderTitle", \(listTitle.queryFragment) AS "listTitle"
"""
}
}
public init(decoder: inout some StructuredQueries.QueryDecoder) throws {
public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws {
let reminderTitle = try decoder.decode(String.self)
let listTitle = try decoder.decode(String.self)
guard let reminderTitle else {
Expand Down Expand Up @@ -123,19 +123,19 @@ extension SnapshotTests {
var date: Date
}

extension ReminderDate: StructuredQueries.QueryRepresentable {
public struct Columns: StructuredQueries.QueryExpression {
extension ReminderDate: StructuredQueriesCore.QueryRepresentable {
public struct Columns: StructuredQueriesCore.QueryExpression {
public typealias QueryValue = ReminderDate
public let queryFragment: StructuredQueries.QueryFragment
public let queryFragment: StructuredQueriesCore.QueryFragment
public init(
date: some StructuredQueries.QueryExpression<Date.ISO8601Representation>
date: some StructuredQueriesCore.QueryExpression<Date.ISO8601Representation>
) {
self.queryFragment = """
\(date.queryFragment) AS "date"
"""
}
}
public init(decoder: inout some StructuredQueries.QueryDecoder) throws {
public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws {
let date = try decoder.decode(Date.ISO8601Representation.self)
guard let date else {
throw QueryDecodingError.missingRequiredColumn
Expand Down Expand Up @@ -178,19 +178,19 @@ extension SnapshotTests {
var date: Date
}

extension ReminderDate: StructuredQueries.QueryRepresentable {
public struct Columns: StructuredQueries.QueryExpression {
extension ReminderDate: StructuredQueriesCore.QueryRepresentable {
public struct Columns: StructuredQueriesCore.QueryExpression {
public typealias QueryValue = ReminderDate
public let queryFragment: StructuredQueries.QueryFragment
public let queryFragment: StructuredQueriesCore.QueryFragment
public init(
date: some StructuredQueries.QueryExpression<Date.ISO8601Representation>
date: some StructuredQueriesCore.QueryExpression<Date.ISO8601Representation>
) {
self.queryFragment = """
\(date.queryFragment) AS "date"
"""
}
}
public init(decoder: inout some StructuredQueries.QueryDecoder) throws {
public init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws {
let date = try decoder.decode(Date.ISO8601Representation.self)
guard let date else {
throw QueryDecodingError.missingRequiredColumn
Expand Down
Loading