How to translate this sql to query builder statments?

insert into tree_path (ancestor, descendant, path_length)
select ancestor, $new_id, path_length + 1
from tree_path
where descendant = $node_id
union
select $new_id, $new_id, 0

assume that there is a model tree_path for the table tree_path, thanks.

I think that you could creat procedure .