Skip to content

Conversation

@mkleczek
Copy link
Contributor

Fixes #4236

@mkleczek mkleczek force-pushed the selflinks branch 4 times, most recently from 59fde2e to e115bb3 Compare January 14, 2026 04:57
@mkleczek mkleczek changed the title feat: Self links add: Self links Jan 14, 2026
Comment on lines +278 to +290
let -- Build an array of "key=eq.value" parts for non-null PK columns using direct column refs.
buildPart col =
SQL.sql (encodeUtf8 $ pgFmtLit (col <> "=eq.")) <> " || (" <> (fromQi table <> "." <> pgFmtIdent col) <> "::text)"
partsArr = "array_remove(ARRAY[" <> intercalateSnippet ", " (buildPart <$> pkCols) <> "], NULL)"
-- Use the base table name for the path (strip trailing _N aliases like clients_1 -> clients)
tblName = qiName table
parts = T.splitOn "_" tblName
baseName = case reverse parts of
(s:rest) | T.all isDigit s && not (null rest) -> T.intercalate "_" (reverse rest)
_ -> tblName
urlExpr = "CASE WHEN array_length(" <> partsArr <> ",1) = 0 THEN NULL ELSE " <>
SQL.sql (encodeUtf8 $ pgFmtLit ("/" <> baseName)) <>
" || '?' || array_to_string(" <> partsArr <> ", '&') END"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we already have logic elsewhere to create Location headers, which should result in very similar URIs. We should probaly re-use the same URI generator for both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should clarify how would this feature be useful (ref) before going to the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

HATEOAS Resource Embeddings (_self link)

3 participants