volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.76k stars 547 forks source link

Allow generation for tables without a Primary Key (ie: Timescale's Hypertables) #1408

Open Serjlee opened 3 months ago

Serjlee commented 3 months ago

I know this was already labeled as a "won't do" in https://github.com/volatiletech/sqlboiler/issues/75#issuecomment-265070783, but I recently stumbled upon a proper use case when dealing with Timescale's Hypertables: for those, primary keys degrade performance and have little use, as foreign keys pointing to hypertables are not allowed.

Even without PKs sqlboiler would still be very valuable to provide generated types, constants, where helpers and perform queries in a consistent way.

I found a okay-ish workaround by using a View defined as select * from my_table_without_pk, but this causes all columns of the generated type to be nullable, which is quite annoying,

Is it something you might plan to reconsider? I tried to implement it myself but so far I failed to produce anything useful

stephenafamo commented 3 weeks ago

Well... now that there is support for views, it should be possible.

The thing would be to read the tables as usual, and then add any table without a primary key to the views.

Serjlee commented 3 weeks ago

Thanks for considering it, I'll then try again to write a PR as soon as I have time for it