seancorfield / next-jdbc

A modern low-level Clojure wrapper for JDBC-based access to databases.
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/
Eclipse Public License 1.0
750 stars 89 forks source link

Allow `:fk-suffix` to work with `as-kebab-maps` #280

Closed sheluchin closed 1 month ago

sheluchin commented 2 months ago

Is your feature request related to a problem? Please describe. https://github.com/seancorfield/next-jdbc/issues/267 added :schema-opts options which allow specifying an alternate :fk-suffix. This works well, but there's a problem when using {:builder-fn rs/as-kebab-maps}, since regardless of what :fk-suffix is, it's still expected to be preceded by an optional _, but as-kebab-maps replaces all underscores with hyphens. When you run a query your result set might have something like {:contact/address-id 42}, but using nav on that field won't get you the corresponding address record.

Describe the solution you'd like I think it would be enough to check for either an optional underscore or an optional hyphen hyphen preceding the fk suffix. Maybe it would be worth it to make this part configurable as well, but I personally don't need that. I supsect underscores + hyphens covers the vast majority of cases.

@seancorfield suggested it could be a simple regex adjustment here along with a mention in the docs:

https://github.com/seancorfield/next-jdbc/blob/9e914bc5e1311e137ea6aed6a539a49e1b7f900a/src/next/jdbc/result_set.clj#L1040