Skip to content
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

Decoding JSONB_AGG_STRICT does not work currently #494

Open
thoven87 opened this issue Jul 22, 2024 · 0 comments
Open

Decoding JSONB_AGG_STRICT does not work currently #494

thoven87 opened this issue Jul 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@thoven87
Copy link

thoven87 commented Jul 22, 2024

Describe the issue

Try decoding JSONB_AGG_STRICT fails

Vapor version

N/A

Operating system and version

macOS 15.0

Swift version

Swift Package Manager - Swift 6.0.0-dev

Steps to reproduce

say you one has the followings:

struct Person: Codable {
    let name: String,
    let id: Int,
    let createdAt: Date
 }

struct Team: Codable, Equatable, PostgresCodable {
    let id: Int
    let peers: [Person]
 }

Decoding logic

let stream = try await self.client.query(
"""SELECT
  team.id,
  JSONB_AGG_STRICT( -- DROP NULL VALUES
    JSON_BUILD_OBJECT(
      'name', people.name,
      'id', people.id,
      'createdAt', people.created_at
    )
  ) AS team_mates
FROM profiles.team t
JOIN profiles.people p
ON t.id = p.team_id
GROUP BY 1"""
)
let team = [Team]
for try await (teamID, teamMates) in stream.decode((Int, [Person]).self) {
 team.append(
    .init(
        id: teamID,
        peers: teamMates
    )
  )
 }


### Outcome

The program will throw Runtime exception 

message=Swift.DecodingError.typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Dictionary<String, Any> but found an array instead.", underlyingError: nil))

Instead of outputting 

and array of Team

### Additional notes

_No response_
@thoven87 thoven87 added the bug Something isn't working label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant