<@!845250139706753044> another random question: ar...
# help
n
@User another random question: are
Date
objects stored as
timestamptz
in Supabase turned back into
Date
objects when queried? It seems like they're always going to be ISO strings (JSON-ified by Postgrest). Is that correct? That seems like a bad API surface for your SDK IMO...
b
@User another random question: are
Date
objects stored as
timestamptz
in Supabase turned back into
Date
objects when queried? It seems like they're always going to be ISO strings (JSON-ified by Postgrest). Is that correct? That seems like a bad API surface for your SDK IMO...
I really have no idea here, I'd have to try it out and see.
n
It looks like it is.
I think I'll create a GitHub issue for this.
Because it'd be nice if the
supabase-js
SDK could figure that out and wrap those ISO strings with JS
Date
objects at runtime.
b
Over the past 5 years or so, I stopped using date fields altogether, and just stored everything using
+new Date()
, so everything is a unix timestamp. But now I'm moving back to date fields since I'm back in PostgreSQL
n
WDYM
+new Date()
?
b
If you do
+new Date()
in Javascript, you get the current unix timestamp, which is just a
long
, which is what I store in my data.
n
Oh, right, I see.
That's like a bitwise operator or som right?
b
no, I think it's just a weird syntax I picked up somewhere
not sure why it's like that.
n
huh
ok, but postgresql has timestamptz and i think that postgrest automatically processes iso strings to be dates and then stores them as timestamps properly
b
so the Supabase js cilent returns a javascript
Date
object from the data?
n
but then the supabase client doesn't know that
and it returns a string from the data
so no, no
Date
objects here
(at least, in nested types)
b
I'm confused. What data type does the javascript client receive from the
.select()
?
n
Copy code
pgsql
create type timeslot (
  from timestamptz,
  to timestamptz
);
create table meeting (
  time timeslot not null
);
it gives me a
string
for the
time.from
and
time.to
properties
b
what would you expect it to return?
date
objects?
n
yup
bc thats what i saved it as
and bc those fields r
timestamptz
types in postgresql
b
I can see your argument. Make an issue for it and see if Steve or the Postgrest people have a reason for it to be string.
n
that should be in the
supabase/postgrest-js
repo right?
b
Does
timestamptz
return a
Date
?
yes
n
u mean if i dont have the nested
timeslot
type?
and j have a
timestamptz
col?
lemme see....
b
but
timeslot
returns a string?
n
nah,
timeslot
is an obj
with
from
and
to
props that are strings
but should be dates
b
so
timestamptz
returns a
Date object
but
timeslot
returns `String`s
n
yes to the second thing
b
oh, I see now
n
im not sure to the first
that's what im checking rn
b
yeah post this one. It's a pretty obscure data type, but your point is valid.
n
yup, all
timestamptz
fields are returned as strings by the supabase js client
j confirmed smh
b
ok, so if
timestamptz
is returned as a string, then it's consistent that
timeslot
return a string too.
n
yeah
but i think that both should be dates
b
You can post this, but they may not agree. I'm not the
Postgrest
expert so I'll leave it for them to debate.
n
or perhaps that the client should error if you try to store
Date
objects in
timestamptz
fields instead of ISO strings
that way, you always get back exactly what u stored
b
I always hated dealing with dates, that's why I converted everything to UNIX timestamps. Then it's just a big number. 🙂
n
bahahahaha yeah makes sense
cause literally every database has their own random date wrapper
(e.g. Firestore has their
Timestamp
object)
b
DOH! Steve just responded, and it makes total sense --
Postgrest
returns
JSON
, and
JSON
doesn't have
DATE
objects.