In SQLDelight, I have a `moduleA` that contains a ...
# squarelibraries
k
In SQLDelight, I have a
moduleA
that contains a table definitions. I would like to write some queries for those tables in a separate
moduleB
. Is it possible? I had found
dependency(project(":path"))
option and I tried to use it, however when I try to reference a table in a
.sq
file it fails to resolve it. Is there anything I’m missing?
I just realized, that this API has different usage, so seems like it's not a solution to my issue
h
What do you mean? It works fine 🤔 Which version do you use?
k
I mean, it works fine when you want to have additional tables definition in
moduleB
that you want to include in Database that is defined in
moduleA
. I would like to achieve something different - get access to tables created in
moduleA
from
moduleB
. Lets say in
moduleA
I have:
Copy code
CREATE TABLE hockeyPlayer (
  player_number INTEGER NOT NULL,
  full_name TEXT NOT NULL
);
in
moduleB
i would like to be able to write:
Copy code
selectAll:
SELECT *
FROM hockeyPlayer;
h
This simple use case should work: Here is the test https://github.com/cashapp/sqldelight/tree/master/sqldelight-gradle-plugin/src/test/diamond-dependency and I use this in some projects too. So just create an issue and a reproducer please 🙂 Or provide some more information
k
Thank you for an example I will take a look at this and I’m sure there must be something wrong in my configuration 🙂
h
Okay, I found the issue with the shared demo project: You are defining the tables in moduleA and the queries using the tables in moduleB. But your gradle files say the opposite: the db of moduleA should depend on the db of moduleB. You must replace the
dependency(project(":moduleB"))
to moduleB with this content:
dependency(project(":moduleA"))
and the same with the
implementation
. The error was very easy to overlook :D
k
Now I get it, thank you so much! I wrongly though it should work other way around 🙂 Sadly IDE still doesn’t see a table, so it lacks autocomplete, but it’s something I can live with 😄