-
Notifications
You must be signed in to change notification settings - Fork 358
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
How to reference a Table which is in another package? #2871
Comments
Let me explain why I want to do this: I'm writing a dart full stack application (meaning shelf back-end, flutter mobile app and flutter web) and I want to place the shared code - such as the data model definition - in a library, then import them in the shelf project and flutter project. However I realized that drift doesn't seem to allow it. I'm currently using floor and trying drift for the first time today, because drift supports not only sqlite but also mysql or postgresql - obviously, it's not a good idea to use sqlite on the backend. |
This is something that should generally work, but requires a bit of setup. The package containing
One thing worth mentioning is that drift's generator is monolithic by default - it generates all the code into a single part file, the one for the database. So all the generated table classes and so on would be duplicated if both the server and the client are declaring a drift database. A solution is to use modular builds, in which drift will generate multiple files and actually allow sharing data classes. |
Thanks. However, adding I solved the problem by moving the database class to the shared package. |
I've also pushed an example using two different database packages sharing some definitions in af55bd0. |
@simolus3 thanks. I did not run builder in the shared package. |
Describe the bug
When Tables and the Database are in different packages, build always fails with the following warning:
When the Tables are placed in the same package, the build will success.
The text was updated successfully, but these errors were encountered: