syncstorage-rs icon indicating copy to clipboard operation
syncstorage-rs copied to clipboard

Replace database-related trait objects with generics

Open ethowitz opened this issue 3 years ago • 1 comments

With the completion of #1277, the database backend (either MySQL or Spanner) will be fixed at compile time instead of runtime, so we will no longer need to support runtime heterogeneity with trait objects. Specifically, there are many places in the code where we use trait objects to support any implementers of the Db and DbPool traits dynamically. With the addition of spanner and mysql feature flags, we will know at compile time whether we're using MySQL or Spanner, and thus, we'll be able to replace the trait objects with generics.

More information about when to use generics vs. trait objects can be found here

┆Issue is synchronized with this Jira Task

ethowitz avatar Jun 09 '22 20:06 ethowitz

➤ Ethan Donowitz commented:

This is a bit more complicated than the ticket explains. We do still need to support heterogeneity in order to use both MockDb and MysqlDb/SpannerDb in the same field in unit tests, so a trait object is still required. I’ll leave this open for now, but I think we may end up keeping the trait object.

data-sync-user avatar Oct 03 '22 23:10 data-sync-user