Похожие чаты

Hi, I have two database tables like this 1) libraries = (

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 , ... )

7 ответов

3 просмотра

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

Masoud- Автор вопроса
drunktimelord
func dependency_tree(library) deps = [] di...

thanks , but I mean in database level (sql query) 😊

Masoud- Автор вопроса
drunktimelord
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

drunktimelord
damn is that even possible

It depends on the db you are using. Some of them have recursive queries (e.g. PostgreSQL)

Masoud- Автор вопроса
drunktimelord
damn is that even possible

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

Похожие вопросы

Обсуждают сегодня

Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
We heading to 1.1$ 🤔?
CryptoBo$$
35
A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
45
Сonst magicTgHTML = (text, entities) => { let processedText = text; let offsetShift = 0; entities.forEach(entity => { const { offset, length, type, url, ...
Андрей
1
кто-то пользуется компонентами rx ? как их лучше ставить, через OPM? (lazarus)
Iluha Companets
15
But what if some projects may have no sense financially but important from public relations point of view and overall adoption (which leads to more investors so more income). ...
Katu
3
Поставил генту, установил кланг, когда запускаю его не давая ему файла он выводит странную ошибку, в чем может быть дело? max@gentoo ~> clang /usr/bin/x86_64-pc-linux-gnu-ld.b...
молодой базз
8
Здравствуйте товарищи! решил всё таки поставить линукс. Порядок создание разделов /boot/efi 200МиБ; /boot 1000; подсистему / 80000; swap 8Гб Будет норм?
K2
19
How Will #Monero Be Attacked? First of all I want to tell you that this is not teaching the network attackers, the central regulators. They already know how to attack the net...
Li₿ΞʁLiøη
3
подскажите пожалуйста, как мне освободить результат записанный в переменную result? в чем проблема подскажите если МОЖЕТЕ?
Михаил Helper
28
Карта сайта