- Notifications
You must be signed in to change notification settings - Fork 978
Open
Labels
Description
A domain is "essentially a data type with optional constraints". You can think of them as type aliases. By using a domain, you can easily create custom types. For example, here's how you could create a KSUID type.
CREATEDOMAINksuidASVARCHAR(27) NOT NULL; CREATETABLEfoo ( id ksuid PRIMARY KEY, created_at TIMESTAMP DEFAULT NOW() ); CREATETABLEbar ( id ksuid PRIMARY KEY, created_at TIMESTAMP DEFAULT NOW(), foo_id ksuid REFERENCES foo(id), name textNOT NULL, slug textNOT NULL UNIQUE );The advantage to using a domain is that you'd only need one entry in overrides
overrides: - db_type: "ksuid"go_type: "github.com/segmentio/ksuid.KSUID"Replaces #418
sbres, ogham, christeredvartsen, mishuk-sk, SoMuchForSubtlety and 4 more