Open chimon2000 opened 1 month ago
@chimon2000 I think the pattern you've used in: https://github.com/chimon2000/notes_nitric, is a good demonstration of database sharing can be achieved for Dart.
Applying recommendations for Option 2 in: https://github.com/nitrictech/cli/issues/812 and updating the Dart guides for resource sharing are probably the best way to address this.
Bug Report
Issue
Upon deploying, I see the following runtime error when attempting to hit an endpoint that pulls data from the SQL Database:
This occurs because I define a shared global resource for the database accessed inside a method handler.
The hypothesis posed by @tjholm is that globally defined variables are lazily evaluated. We could verify this by reassigning the database resource inside of
main
:Other resources such as the previously defined
api
don't have this problem because they are initialized or referenced directly inside of themain
function for each service.Steps
Steps to reproduce the behavior:
Attempt to deploy the following project: https://github.com/chimon2000/db-deploy-issue
Expected
The database is created and seeded before the API is referenced.
Environment and setup information
Other info
Conversation thread: https://discord.com/channels/955259353043173427/999455789146181683/1287084311916445727