HarryET
10/28/2021, 9:48 PMmadx
10/28/2021, 10:51 PMsupabase-js
and I found out that it would be great to have a way to convert the casing in responses (Postgres convention is snake_case
Β while JS's one is camelCase
for example) to match the language's conventions.
This is something that some ORMs provide, such as Objection https://vincit.github.io/objection.js/recipes/snake-case-to-camel-case-conversion.html
In the meantime, I hacked a custom replacer using proxies:
js
function withCamelCase(builder) {
return new Proxy(builder, {
get: (target, prop, receiver) => {
if (prop === "then") {
return (...args) =>
target
.then((response) => ({
...response,
data: camelCase(response.data, { deep: true }),
}))
.then(...args)
}
if (typeof target[prop] === "function") {
return (...args) => withCamelCase(target[prop](...args))
}
return Reflect.get(target, prop, receiver)
},
})
}
export default () => {
const client = createClient(SUPABASE_URL, SUPABASE_KEY)
return withCamelCase(client)
}
florian-lefebvre
11/01/2021, 3:30 PMflorian-lefebvre
11/01/2021, 3:31 PMgaryaustin
11/02/2021, 12:59 AMcopple
11/02/2021, 8:41 AMuser
11/03/2021, 3:22 AMIllia
11/04/2021, 9:46 AMchipilov
11/04/2021, 9:58 AMdiscoding
11/08/2021, 7:44 AMuseSWR
is used for caching data. Just a thought πMi3LiX9
11/08/2021, 3:49 PMkawallis
11/09/2021, 6:02 PMPragy
11/10/2021, 3:36 PMchipilov
11/10/2021, 4:18 PMPragy
11/10/2021, 4:26 PMPragy
11/10/2021, 4:27 PMchipilov
11/10/2021, 4:28 PMHarryET
11/12/2021, 7:00 PMsilentworks
11/12/2021, 8:28 PMuser
11/12/2021, 10:05 PMHarryET
11/14/2021, 2:54 PMrahat
11/16/2021, 8:43 PMOlyno
11/16/2021, 11:59 PMcopple
11/17/2021, 11:59 AMHarryET
11/17/2021, 4:28 PMcoozamano
11/17/2021, 6:44 PMScott P
11/17/2021, 7:24 PMcoozamano
11/18/2021, 4:31 PMryexley
11/18/2021, 4:34 PMEscape
should dismiss that dialog, doesn't it?