id , name )
2) library_library = ( library_id , required_library_id )
libraries = a list of javascript libraries
library_library = a pivot table for keeping library dependencies
my question is how do I can get nested (recursive) dependencies for a library ?
( library 1 => 5 , 5 => 8 , ... )
func dependency_tree(library) deps = [] direct_deps = query_deps(library) for dep in direct_deps: deps = append(deps, {lib: library, deps: dependency_tree(dep)}) return deps
thanks , but I mean in database level (sql query) 😊
damn is that even possible
merging what you said with sql query is also possible 🤔 but eventually I need sql query for that and thats my problem
It depends on the db you are using. Some of them have recursive queries (e.g. PostgreSQL)
WITH library_deps AS ( select required_library_id, 1 as depth from library_library where library_id = 35 and dependency_type = 'preloaded' UNION ALL select library_library.required_library_id, library_deps.depth + 1 from library_deps join library_library on library_deps.required_library_id = library_library.library_id ) ------------------ only need distinct----------------- SELECT required_library_id as library_id FROM library_deps order by depth desc
Обсуждают сегодня