Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Type brands for primary/foreign keys #40

Open
aleclarson opened this issue Oct 7, 2022 · 0 comments
Open

Type brands for primary/foreign keys #40

aleclarson opened this issue Oct 7, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@aleclarson
Copy link
Contributor

aleclarson commented Oct 7, 2022

Goal: Extra type safety. Prevent primary keys for one table from being used in a query of another table.

// The generated type of a primary/foreign key
id: t.int4 & t.key<'user.id'>

To convert an external value into a branded key:

// Note: Falsy values are passed through.
const userId = t.user.id(req.searchParams.get('userId'))

Casting like what's shown above doesn't include runtime validation. This is only for type safety.

@aleclarson aleclarson added the enhancement New feature or request label Oct 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant