Hello Jeremy
Thank you for your advice.
>
>
>> So I would like to know much about rcte_tree plugin.
>>
>> Question
>> Could you tell me common method to find specified node like ("/a/b/c")
>> with rcte_tree?
>> Please tell me if you know alternative approach.
>>
>
> There's not a common method. A simplistic approach with multiple queries:
>
> Node.first(:name=>'a', :parent_id=>nil).
> children_dataset.first(:name=>'b').
> children_dataset.first(:name=>'c')
>
I wrote find_from_top method.
I want to simplify this. but It seems work fine.
def traverse_to_leaf(tree,node)
ret = nil
return node if tree.empty?
cur_name = tree.shift
leaf = node.children_dataset.first(:name => cur_name)
if( leaf )
ret = traverse_to_leaf(tree,leaf)
end
ret
end
def find_from_top(search_path)
root = FileTree.root
nodes = search_path.split('/')[1..-1]
traverse_to_leaf(nodes,root)
end
>
> An approach using joins:
>
> Node.join(:nodes___n1, :parent_id=>:id).
> join(:nodes___n2, :parent_id=>:id).
> first(:nodes__name=>'a', :n1__name=>'b', :n2__name=>'c')
>
joins approach seems good.
But I'm not sure how to add multiple path dynamically.
I'll check it.
Thank you so much again.
--
Hiroyuki Sato.
>
> I'm guessing the join approach is faster, but I don't know enough about
> SQLite's query optimizer to say for sure, you'd have to test.
>
> I implemented two method. (find_node_recursive and find_node_ancestors)
>>
>> Is it possible to use ancestors method for that?
>> (Is it return sorted node list?)
>>
>
> The CTE query itself will return rows in that order, since that is the
> order it calculates the rows. I think most databases will return the rows
> in the same order, but I'm not sure about that, you'd have to test.
>
>
>>
>> Thanks
>> --
>> Hiroyuki Sato.
>>
>>
>> P.S.
>> FYI
>> rcte_tree plugin does not work OSX marveriks until install sqlite3 >=
>> 3.8.3 by myself.
>> bundled version is 3.7.13 and it does not support supports common
>> table expressions.
>>
>
> Yes, I'm aware. Sequel only turns on CTE support on SQLite if version is
> >= 3.8.3.
>
> Thanks,
> Jeremy
>
2014年6月27日金曜日 13時32分55秒 UTC+9 Jeremy Evans:
>
> On Thursday, June 26, 2014 8:17:57 PM UTC-7, Hiroyuki Sato wrote:
>>
>> Hello Jeremy
>>
>> Thank you for your advice.
>>
>> I'll think to store the path as a column.
>> It seems faster then rcte_tree for search path.
>>
>> But I'm wondering move operation slower than rcte_tree
>>
>
> Correct, as this would require changing the path for all files/directories
> under that path. You can probably do this in a single query though using
> substr with string concatenation, though, so I'm not sure it would perform
> much worse unless there are a large number of rows that need to be updated.
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.