sql

sheluchin 2023-12-04T16:04:02.770289Z

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?

seancorfield 2023-12-07T06:09:46.823449Z

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.

sheluchin 2023-12-07T13:28:03.667039Z

@seancorfield thanks very much!

seancorfield 2023-12-04T16:30:46.985309Z

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

sheluchin 2023-12-04T16:36:08.768859Z

@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.

seancorfield 2023-12-04T17:17:56.833359Z

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?

sheluchin 2023-12-04T17:20:00.757259Z

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

seancorfield 2023-12-04T17:29:47.973059Z

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

sheluchin 2023-12-04T17:33:09.927189Z

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

sheluchin 2023-12-04T21:58:24.292829Z

https://github.com/seancorfield/next-jdbc/issues/267

👍🏻 1
seancorfield 2023-12-04T22:02:14.467049Z

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)

seancorfield 2023-12-04T22:03:01.063889Z

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