Handling Foreign Key Dependencies in Schema Design: Best Practices
Hey There! I have a Schema which includes something like a foreign key in an database:
ˋˋˋts
const Foo = S.Struct({
...
barID: S.string,
....
})
ˋˋˋ
Addititionally, I have a Dependency (something I can via ˋEffect.provideContext(..., ...)ˋ) that offers a method ˋlookupBar: (barID) => Effect.Effect<Bar, BarError, never>ˋ
Consequently could create another Schema:
ˋˋˋ
const BarFromID = S.transformOrFail(
S.string,
Bar,
{
decode: (str: string) => // using lookupBar from the dependency here
// and parse as usual
}
)
ˋˋˋ
That would result in a "Schema with Database Dependencies" and that feels somewhat wrong? Is that a bad Idea? What the recommened way to handle those kinds of references?
ˋˋˋts
const Foo = S.Struct({
...
barID: S.string,
....
})
ˋˋˋ
Addititionally, I have a Dependency (something I can via ˋEffect.provideContext(..., ...)ˋ) that offers a method ˋlookupBar: (barID) => Effect.Effect<Bar, BarError, never>ˋ
Consequently could create another Schema:
ˋˋˋ
const BarFromID = S.transformOrFail(
S.string,
Bar,
{
decode: (str: string) => // using lookupBar from the dependency here
// and parse as usual
}
)
ˋˋˋ
That would result in a "Schema with Database Dependencies" and that feels somewhat wrong? Is that a bad Idea? What the recommened way to handle those kinds of references?
