question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I perform recursive queries?

See original GitHub issue

I have a database with a hierarchical recursive structure. This is what my schema looks like:

@schema.register
class HierarchyChild(SQLAlchemyNode):
    class Meta:
        model = HierarchyModel

@schema.register
class Hierarchy(SQLAlchemyNode):
    class Meta:
        model = HierarchyModel

    children = SQLAlchemyConnectionField(HierarchyChild)

Currently this returns nested results, however, it doesn’t pass the parent context to the child node. Thanks in advanced!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
davidsims9tcommented, Nov 13, 2016

Sure thing. It was pretty simple actually. So I just used:

class Hierarchy(SQLAlchemyObjectType):
    class Meta:
        model = HierarchyModel
        interfaces = (relay.Node, )

    children = SQLAlchemyConnectionField(lambda: Hierarchy)

    def resolve_children(self, args, context, info):
        return HierarchyModel.query.filter(HierarchyModel.parent_tsn.in_([self.tsn])).all()

If I use just use Hierarchy without using lambda, Hierarchy is undefined.

0reactions
cliedemancommented, Nov 12, 2016

Glad you got it working Would you mind pasting a sample for future readers?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recursive query example - IBM
A recursive query is one that is defined by a Union All with an initialization fullselect that seeds the recursion. The iterative fullselect...
Read more >
Recursion in SQL Explained Visually | by Denis Lukichev
Recursion is achieved by WITH statement, in SQL jargon called Common Table Expression (CTE). It allows to name the result and reference it ......
Read more >
Recursive queries - SQL Workbench/J
Recursive queries are used to query hierarchical data. The SQL standard defines a special syntax for common table expressions to enable recursive processing ......
Read more >
Hierarchical and recursive queries in SQL - Wikipedia
A hierarchical query is a type of SQL query that handles hierarchical model data. They are special cases of more general recursive fixpoint...
Read more >
Recursive SQL Expression Visually Explained - Built In
Recursive SQL refers to the use of a recursive common table expression (CTE) in SQL, a query that continuously references a previous result ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found