sql 2023-12-04

By default, next.jdbc assumes that a column named <something>id or <something>_id is a foreign key into a table called <something> with a primary key called id.
https://github.com/seancorfield/next-jdbc/blob/develop/doc/datafy-nav-and-schema.md#identifying-foreign-keys Is there a way to change the expected suffix from id/`_id` to something else without doing so manually for each key in :schema?

The latest develop branch and SNAPSHOT on Clojars support a new :schema-opts option that lets you override the :fk-suffix and the :pk column name. I expect to cut a release before the holidays.

No. You're the first to ask. What naming convention would you like here?

@seancorfield I happened to have used did instead of id. Not too late to change it on my end, but I was just looking for the shortest path to get datafy working.

Interesting. Right now the suffix is tied to the expected column name in the other table too, so foo_id would join to foo.id. I wonder if there's a use case where the suffix and the key column name don't match? In your case, is it foo_did and foo.did?

Yes, in my case they match, but I see your point, they could be different.

Create a GH issue and I'll take a look and see how easy it would be to use different suffix values.

Will do, @seancorfield. Thanks for hearing me out.

I'll probably add a :schema-opts option that takes a hash map where you can specify both the foreign key column suffix and the primary key column name, so you can change them independently. I may also add an option to support a PK as <table><suffix> (which I hate but I've seen some databases using)

I'll have to give it some thought...