Contract translation for use in an external system


I'd like to mirror Racket contracts on the SQLite side for a proof-of-concept dataframe library. Any type can be inserted in any column in SQLite, although types can optionally be enforced at runtime through triggers and CHECK constraints.

So conceptually, here's a brief depiction of what I have up to now:

A dataframe is a (possibly dependently) contracted struct

#lang racket

(struct df (col1 col2 col3))

(define dataframe
 (struct/dc df
                    [col1 any/c]
                    [col2 (col1) (>/c col1)]
                    [col3 (col1 col2) (between/c col1 col2)]))

From there, I'm doing some very brittle parsing of the contract to construct SQLite triggers.

Now, except when running SELECT statements, I don't materialize any data on the Racket side. Everything stays in the database so I've no real need for df itself since it will never be instantiated. I only need the contract!

What would be a good way to reflect Racket contracts on the SQLite side in a consistent manner?

I hope I'm making at least a little sense... :sweat_smile: