-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
The JS SDK adds the s parameter to all parameters provided as a string; this prevents Surreal from inferring types and forces a difference between the input and output schemas for a table. This causes errors with our schema definitions as we are expecting to be able to pass a date string to date fields but this will throw an error:
await db.query(`DEFINE TABLE test SCHEMAFULL; DEFINE FIELD time ON test TYPE datetime; DEFINE FIELD relation ON test TYPE record<test>;`)
//fails
await db.create("test", {
relation: new RecordId("test", "123"),
time: new Date().toIsoString()
})
// successful
await db.create("test", {
relation: new RecordId("test", "123"),
time: new Date()
}) But our generated type for this table would be
z.object({
relation: recordId('test'),
time: z.string().datetime()
})Barring a change to the SDK I think the best approach is likely to create a custom Zod type for dates similar to the recordId type which applies a transform and converts the value to a date; this would allow us to provide a string or date object argument for datetime fields.
Metadata
Metadata
Assignees
Labels
No labels