Home > database >  Share database connection between many structs
Share database connection between many structs

Time:12-25

In my program I need to share connection between many struct for updating data in database.

I use rusqlite for my database and egui for my GUI

Here my source code.

I put a FIXME in the file counter.rs.

I implemented Widget for displaying data easily. And when I click on a button I would like to perform a SQL UPDATE ... request but I cannot get database connection.

Thank for you help.

I think I found a solution with the singleton DP but I think it's a bad way to do it.

CodePudding user response:

You may want to separate data from interface - create a separate struct for the Counter UI which holds a DB reference and a copy of the Counter data. Then you can straightforwardly construct such a Counter UI object when you instantiate your counter app, passing your DB connection onwards.

  • Related