Skip to content

Commit 29acee0

Browse files
committed
refactor: add PostgreSQL.Array namespace for organization
Adds PostgreSQL.Array namespace to avoid potential conflicts with Swift.Array. The existing Array function implementations were already excellent with: - ✅ Swifty naming (.appending(), .removing(), .replacing()) - ✅ @_disfavoredOverload on .joined() to prevent stdlib conflicts - ✅ Comprehensive PostgreSQL Chapter 9.19 coverage - ✅ Well-organized into 4 files by function category ## Changes - Added Array/Array.swift with PostgreSQL.Array namespace definition - Documented dual API pattern (namespace vs method style) - No changes to existing implementations (already perfect) ## No Stdlib Conflicts - .contains() - Different signature (array literals vs predicates) - .joined() - Already has @_disfavoredOverload - .count - Not implemented (using .arrayLength()/.cardinality() instead) - .append() - Not a conflict (.appending() returns new array) ## Test Results ✅ All 860 tests passing ✅ Existing Array functions work perfectly ✅ Ready for future namespace-style static methods if needed
1 parent 0bbb660 commit 29acee0

File tree

1 file changed

+39
-0
lines changed
  • Sources/StructuredQueriesPostgres/Functions/Array

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Foundation
2+
import StructuredQueriesCore
3+
4+
// MARK: - PostgreSQL Array Functions Namespace
5+
//
6+
// PostgreSQL Chapter 9.19: Array Functions and Operators
7+
// https://www.postgresql.org/docs/18/functions-array.html
8+
//
9+
// ## Organization (Matches PostgreSQL Chapter 9.19)
10+
//
11+
// - **Construction**: array(), emptyArray(), append(), prepend(), concatenate()
12+
// - **Operators**: @>, <@, &&, ||, =, <>, <, >
13+
// - **Manipulation**: removing(), replacing(), joined(), toJSON()
14+
// - **Query**: arrayLength(), cardinality(), arrayPosition(), unnest()
15+
//
16+
// ## Dual API Pattern
17+
//
18+
// All array functions support two calling styles:
19+
//
20+
// **Namespace style:**
21+
// ```swift
22+
// PostgreSQL.Array.contains($0.tags, ["swift"])
23+
// PostgreSQL.Array.append($0.tags, "new-tag")
24+
// ```
25+
//
26+
// **Method style (fluent):**
27+
// ```swift
28+
// $0.tags.contains(["swift"])
29+
// $0.tags.appending("new-tag")
30+
// ```
31+
//
32+
// Both compile to identical SQL. Choose based on context and readability.
33+
34+
extension PostgreSQL {
35+
/// Namespace for PostgreSQL array functions
36+
///
37+
/// This enum cannot be instantiated - it serves purely as a namespace.
38+
public enum Array {}
39+
}

0 commit comments

Comments
 (0)