Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'WITH RECURSIVE' query not generating corresponding data class #2952

Closed
MJegorovas opened this issue Mar 27, 2022 · 0 comments · Fixed by #3097
Closed

'WITH RECURSIVE' query not generating corresponding data class #2952

MJegorovas opened this issue Mar 27, 2022 · 0 comments · Fixed by #3097

Comments

@MJegorovas
Copy link

MJegorovas commented Mar 27, 2022

SQLDelight Version

1.5.3

Operating System

MacOS BigSur 11.6.4 (20G417)

Gradle Version

7.3.0-alpha03

Kotlin Version

1.6.10

AGP Version

No response

Describe the Bug

Using WITH RECURSIVE does not generate required data class for query. Here's my sql:

CREATE TABLE item (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    parent_id INTEGER,
    children INTEGER NOT NULL
);

test:
WITH RECURSIVE
descendants AS (
    SELECT id, parent_id
    FROM item
    WHERE item.id = :id
    UNION ALL
    SELECT item.id, item.parent_id
    FROM item, descendants
    WHERE item.id = descendants.parent_id
)
SELECT descendants.id, descendants.parent_id
FROM descendants;

This also does not work (but changing 7 line to descendants AS ( fixes):

CREATE TABLE item (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    parent_id INTEGER
);

test:
WITH RECURSIVE
descendants(id, parent_id) AS (
    SELECT id, parent_id
    FROM item
    WHERE item.id = :id
    UNION ALL
    SELECT item.id, item.parent_id
    FROM item, descendants
    WHERE item.id = descendants.parent_id
)
SELECT descendants.id, descendants.parent_id
FROM descendants;

Here's generated query class, but Descendants cannot be found (red) as it is not generated.

public interface ItemQueries : Transacter {
  public fun <T : Any> test(id: Long, mapper: (id: Long, parent_id: Long?) -> T): Query<T>

  public fun test(id: Long): Query<Descendants>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants