@@ -115,7 +115,7 @@ extension PrimaryKeyedTableDefinition where QueryValue: Codable & Sendable {
115115 AggregateFunction (
116116 " json_group_array " ,
117117 isDistinct: isDistinct,
118- [ jsonObject. queryFragment] ,
118+ [ jsonObject ( ) . queryFragment] ,
119119 order: order? . queryFragment,
120120 filter: filter? . queryFragment
121121 )
@@ -188,16 +188,18 @@ extension PrimaryKeyedTableDefinition where QueryValue: _OptionalProtocol & Coda
188188 return AggregateFunction (
189189 " json_group_array " ,
190190 isDistinct: isDistinct,
191- [ jsonObject. queryFragment] ,
191+ [ QueryValue . columns . jsonObject ( ) . queryFragment] ,
192192 order: order? . queryFragment,
193193 filter: filterQueryFragment
194194 )
195195 }
196196}
197197
198- extension PrimaryKeyedTableDefinition {
199-
200- fileprivate var jsonObject : some QueryExpression < QueryValue > {
198+ extension TableDefinition where QueryValue: Codable & Sendable {
199+ /// A JSON representation of a table's columns.
200+ ///
201+ /// Useful for referencing a table row in a larger JSON selection.
202+ public func jsonObject( ) -> some QueryExpression < _CodableJSONRepresentation < QueryValue > > {
201203 func open< TableColumn: TableColumnExpression > ( _ column: TableColumn ) -> QueryFragment {
202204 typealias Value = TableColumn . QueryValue . _Optionalized . Wrapped
203205
@@ -240,8 +242,15 @@ extension PrimaryKeyedTableDefinition {
240242 let fragment : QueryFragment = Self . allColumns
241243 . map { open ( $0) }
242244 . joined ( separator: " , " )
243- return SQLQueryExpression (
244- " CASE WHEN \( primaryKey. isNot ( nil ) ) THEN json_object( \( fragment) ) END "
245- )
245+ return QueryFunction ( " json_object " , SQLQueryExpression ( fragment) )
246+ }
247+ }
248+
249+ extension Optional . TableColumns where QueryValue: Codable & Sendable {
250+ /// A JSON representation of a table's columns.
251+ ///
252+ /// Useful for referencing a table row in a larger JSON selection.
253+ public func jsonObject( ) -> some QueryExpression < _CodableJSONRepresentation < Wrapped > ? > {
254+ Case ( ) . when ( rowid. isNot ( nil ) , then: Wrapped . columns. jsonObject ( ) )
246255 }
247256}
0 commit comments