Sqldelight: More detailed documentation on multi-module support

Created on 21 Apr 2019  路  2Comments  路  Source: cashapp/sqldelight

Slowly working on migrating an existing project from 0.9.0 over to 1.1.3. The existing project has a :data module which is where the core database logic resides along with the SupportSQLiteOpenHelper.Callback implementation. However there are other :[feature]:data modules that have their own *.sq files but are ultimately depended on by :data.

I have been struggling to get things working on my end even after trying the sqldelight Gradle DSL that comes with the plugin. I keep running into:

 Cannot depend on a module with no sqldelight plugin

Despite all the modules apply-ing the sqldelight plugin. To try to get a better of sense of things, I decided to create a small Android project where :coredata depends on :featuredata. I got things compiling and the Schema within :coredata appears to include the Schema from :featuredata but my solution looks different than the test example in https://github.com/square/sqldelight/pull/1229/files#diff-016af6af13f80cb56a309f2cb830e588R9.

I was running into:

 Detected a schema that already has the package name com.example in project project ':featuredata'

I wound up having to go with the following:

// From :coredata
sqldelight {
    Database {
        dependency libs.featureData
    }
}
// From :featuredata
sqldelight {
    Database {
        packageName = "com.example"
        schemaOutputDirectory = file('src/main/sqldelight/databases')
    }
}

I still have to try and see if I can get multi-module support working on my original project.

Overall, it would be great to have some more detailed documentation on how to support multi-module projects.

Questions I have are:

  1. Does the database name have to be identical across modules that will be interconnected?
  2. Can I not have CoreDatabase which depends on FeatureDatabase?
  3. For the module where dependency is specified, should all other properties be omitted and only specified in the dependency module directly, as shown in my snippet above?
  4. What are the bare minimum DSL requirements to get multi-module support working? I have had to rely on trial and error along with trying to get up to speed on the Gradle Plugin source code.

Thank you! 馃檪

documentation

Most helpful comment

  1. The database name does have to be identical.
  2. No, the dependency is meant to be "bundle this other schema into my database" so having the same database name felt the most consistent to me. In android it's kind of like sharing variant names, when you depend on a module the debug variant will include debug sources from the dependency
  3. No, you should be able to specify everything you would like.
  4. You are right that the key is the packagename. Again if we're thinking about android its kind of like the manifest package name, it still need to be unique for each database. So the minimum required amount is unique package names, identical database names, and then the dependency.

All 2 comments

  1. The database name does have to be identical.
  2. No, the dependency is meant to be "bundle this other schema into my database" so having the same database name felt the most consistent to me. In android it's kind of like sharing variant names, when you depend on a module the debug variant will include debug sources from the dependency
  3. No, you should be able to specify everything you would like.
  4. You are right that the key is the packagename. Again if we're thinking about android its kind of like the manifest package name, it still need to be unique for each database. So the minimum required amount is unique package names, identical database names, and then the dependency.

Thank you for the reply! I wound up figuring out the details on my own via trial and error. I still think it would be beneficial to include some of these details in the documentation. It might help others who are supporting multi-module get up to speed quicker.

Re:

I keep running into:

 Cannot depend on a module with no sqldelight plugin

That turned out to be https://github.com/square/sqldelight/issues/1317.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikezliu picture mikezliu  路  14Comments

4face-studi0 picture 4face-studi0  路  13Comments

julienbanse picture julienbanse  路  23Comments

AndrewReitz picture AndrewReitz  路  16Comments

eygraber picture eygraber  路  22Comments