Helper that turns a comments table into a threaded list query for one
(resource,row). Returns a SQLAlchemy Select
and registers nothing on metadata — run it directly against a
connection and feed the rows to
fsh_lib.comments.build_comment_thread() to nest them.
Pair with fsh_lib.comments.CommentMixin for the storage
columns (resource_type, resource_id, parent_comment_id,
body, author_id).
The query filters to the one (resource_type,resource_id) and
orders top-level comments (parent_comment_idISNULL) ahead of
replies, each group by created_at.
fsh_lib.comments.build_comment_thread() nests the flat stream
from an id-keyed dict, so the only ordering that matters for the tree
is the order of a parent’s replies — which the sort keeps
chronological. No recursive CTE for the common one-level-deep thread
shape; add one if arbitrary-depth nesting is needed.
Full signature lives in the API reference reference.
Comments queries¶
Helper that turns a comments table into a threaded list query for one
(resource, row). Returns a SQLAlchemySelectand registers nothing on metadata — run it directly against a connection and feed the rows tofsh_lib.comments.build_comment_thread()to nest them.Pair with
fsh_lib.comments.CommentMixinfor the storage columns (resource_type,resource_id,parent_comment_id,body,author_id).What is exposed¶
One function, re-exported at
codegen_database.ext.comments:construct_comments_thread_query()How to use¶
The query filters to the one
(resource_type, resource_id)and orders top-level comments (parent_comment_id IS NULL) ahead of replies, each group bycreated_at.fsh_lib.comments.build_comment_thread()nests the flat stream from an id-keyed dict, so the only ordering that matters for the tree is the order of a parent’s replies — which the sort keeps chronological. No recursive CTE for the common one-level-deep thread shape; add one if arbitrary-depth nesting is needed.Full signature lives in the API reference reference.