Transform Postgres array into JS array

Hey, I was wondering if there's a helper or something to transform Postgres arrays {one, two} into JS arrays ['one', 'two']. Right I know the Postgres array is turned into a string when executing queries
Solution:
Message Not Public
Sign In & Join Server To View
Jump to solution
13 Replies
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Daniel Cruz
Daniel Cruz13mo ago
I'm getting a string. Maybe is the fact that my column type is an enum array?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Daniel Cruz
Daniel Cruz13mo ago
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Daniel Cruz
Daniel Cruz13mo ago
GitHub
ENUM ARRAY types get parsed as single string · Issue #56 · brianc/n...
Hi, I found that currently there is an issue with the way pg-types parses ENUM ARRAY column types. Currently the array is not parsed at all and a simple string is returned with the SQL array serial...
Daniel Cruz
Daniel Cruz13mo ago
do you know how can I define the custom types with Kysely? 😅
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Daniel Cruz
Daniel Cruz13mo ago
Yep, I ended up doing
...
.selectAll("Collection")
.select((eb) => [
sql<string[]>`categories::text[]`.as("categories"),
...
...
.selectAll("Collection")
.select((eb) => [
sql<string[]>`categories::text[]`.as("categories"),
...
As using oid seems brittle, for any reason the id could change between dev and prod
koskimas
koskimas13mo ago
As using oid seems brittle, for any reason the id could change between dev and prod
You mean the data type oid in setTypeParser? It won't change Actually with custom types, I'm not so sure
Daniel Cruz
Daniel Cruz13mo ago
Yeah, the custom type oid was different in my local db and prod db, idk why 🤷‍♂️ but better not to risk it
Igal
Igal13mo ago
This can be more type-safe:
.select((eb) => sql<string[]>`${eb.ref('categories')}::text[]`.as('categories'))
.select((eb) => sql<string[]>`${eb.ref('categories')}::text[]`.as('categories'))
Daniel Cruz
Daniel Cruz13mo ago
You're the best
Want results from more Discord servers?
Add your server
More Posts