pranjal_fxd
pranjal_fxd17mo ago

Typeschecks inside database queries

Hey how can i check if a particular item is in database array
2 Replies
Michal Srb
Michal Srb17mo ago
Hey @pranjal_fxd We don't have typechecks in the database query language. Your options are: 1. Encode the information along with the multi-typed data. You could store {type: "array", value: []}, {type: "string, value "foo"} documents for example 2. Filter the data in JavaScript/TypeScript after collect() Let me know if that helps
ian
ian17mo ago
To expand on (1), you can also store the different types in different fields Your type could look like:
{
data: v.union(
v.object({type: "str", string: "hi"}),
v.object({type: "num", number: 3}),
})
{
data: v.union(
v.object({type: "str", string: "hi"}),
v.object({type: "num", number: 3}),
})
You could have an index on "data.string" like:
q.eq("data.string", "hi")
q.eq("data.string", "hi")
or fetch the ones of a given type like:
q.eq("data.type", "str")
q.eq("data.type", "str")

Did you find this page helpful?