When I try to set a default to to a timestamp I al...
# orm-help
j
When I try to set a default to to a timestamp I always get an error:
Copy code
DateTime?                @db.Timestamp(6)
a
hey Jonathan, the best approach I've found is to use
graphql-scalars
and
@types/graphql-scalars
in your entity/object defs for your models so for phoneNumber, for example, I use
Copy code
PhoneNumberResolver
which throws an error if a phone number field doesn't conform to the international standard E144 format (basically just a "+"-sign with the countrycode before a phone number) so
<tel:+18885551234|+18885551234>
would be accepted, but
18885551234
would throw an error it resolves to a
PhoneNumberScalar
type in the schema same thing applies to ISO-8601 International Time format--I believe it is called a
TimeResolver
in the graphql-scalars package a hacky workaround for getting ISO-8601 starting with a full datetime string would be
Copy code
const getTimestamp = new Date(Date.now()).toISOString();
console.log(getTimestamp)

const getDateOnly = getTimestamp.split(/([T])/)[0];

// the "T" character is at index 1 of this split datetime string
// "2022-02-09T23:13:22.620Z": [0] 2022-02-09 | [1] T | [2] 23:13:22.620Z

const getTimeOnly = getTimestamp.split(/([T])/)[2];

console.log(JSON.stringify({
  isoDate: getDateOnly,
  isoTime: getTimeOnly
}, null, 2))

// don't want the TZ appended on the end? 
const removeTrailingTZCharacter = getTimeOnly.split(/([Z])/)[0];
// outputs [0] 23:13:22.620 (the Z is at index 1)
console.log(removeTrailingTZCharacter);
also try out the
@db.generated("")
approach -- I think it's Timestamp(3) in Postgres...not sure about other databases
j
ok thanks, we aren’t using graphql I will try the
@db.generated("")
Got this error
Copy code
Unable to match input value to any allowed input type for the field. Parse errors: [Query parsing/validation error at `Mutation.createOneaccount.data.accountCreateInput.version`: A value is required but not set., Query parsing/validation error at `Mutation.createOneaccount.data.accountUncheckedCreateInput.version`: A value is required but not set.]
when using
_DateTime_?                @db.Timestamp(_6_) @default(dbgenerated())
the db.timestamp(6) came from a
db pull
on a postgres database