Inline Classes Make Great Database IDs
[]
Jake Wharton
package com.example.db inline class CustomerId ( val value : Long ) inline class InstrumentId ( val value : Long ) inline class PaymentId ( val value : Long ) The payment table also uses these types for its own ID as well as the foreign key IDs to other tables. -- src/main/sqldelight/com/example/db/Payment.sq CREATE TABLE payment ( id INTEGER AS PaymentId PRIMARY KEY , sender_id INTEGER AS CustomerId NOT NULL , recipient_id INTEGER AS CustomerId NOT NULL , instrument_id INTEGER AS InstrumentId NOT NULL , -- other columns… FOREIGN KEY ( sender_id ) REFERENCES customer ( id ), FOREIGN KEY ( recipient_id ) REFERENCES customer ( id ), FOREIGN KEY ( instrument_id ) REFERENCES instrument ( id ) );