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

[PostgreSQL] Storing Arrays of Custom Codable Types as JSONB[] instead of JSONB? #587

Open
Bamakoo opened this issue Nov 23, 2023 · 0 comments
Assignees

Comments

@Bamakoo
Copy link

Bamakoo commented Nov 23, 2023

Hi,

Whilst building a personal, side project I wanted to store an Array of Custom Codable Types.

struct CustomType: Codable {}

the resulting code in the tables' migration made use of the Custom option:

.array(of: .custom(CustomType.self))

All Vapor migrations ran like a charm but whilst testing it using Postman I ran into the following error:

Column custom_type is of type JSONB but expression is of type JSONB[]

Spent hours scouring the web for more info couldn't find any, banging my head against the wall trying to figure out what I was doing wrong with the JSON.

Finally, I reached out to Gwynne of the Vapor Core Team. She suggested swapping :

.array(of: .custom(CustomType.self))

for

.sql(raw: "JSONB[]")

Unsurprisingly, it worked!

Thank you for everything you do for the community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants