mod.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. mod sql_impl;
  2. use crate::RevisionRecord;
  3. use diesel::SqliteConnection;
  4. use flowy_collaboration::entities::revision::RevisionRange;
  5. pub use sql_impl::*;
  6. use flowy_error::FlowyResult;
  7. use std::fmt::Debug;
  8. pub trait RevisionDiskCache: Sync + Send {
  9. type Error: Debug;
  10. fn create_revision_records(
  11. &self,
  12. revision_records: Vec<RevisionRecord>,
  13. conn: &SqliteConnection,
  14. ) -> Result<(), Self::Error>;
  15. // Read all the records if the rev_ids is None
  16. fn read_revision_records(
  17. &self,
  18. object_id: &str,
  19. rev_ids: Option<Vec<i64>>,
  20. ) -> Result<Vec<RevisionRecord>, Self::Error>;
  21. // Read the revision which rev_id >= range.start && rev_id <= range.end
  22. fn read_revision_records_with_range(
  23. &self,
  24. object_id: &str,
  25. range: &RevisionRange,
  26. ) -> Result<Vec<RevisionRecord>, Self::Error>;
  27. fn update_revision_record(&self, changesets: Vec<RevisionChangeset>) -> FlowyResult<()>;
  28. // Delete all the records if the rev_ids is None
  29. fn delete_revision_records(
  30. &self,
  31. object_id: &str,
  32. rev_ids: Option<Vec<i64>>,
  33. conn: &SqliteConnection,
  34. ) -> Result<(), Self::Error>;
  35. // Delete and insert will be executed in the same transaction.
  36. // It deletes all the records if the deleted_rev_ids is None and then insert the new records
  37. fn delete_and_insert_records(
  38. &self,
  39. object_id: &str,
  40. deleted_rev_ids: Option<Vec<i64>>,
  41. inserted_records: Vec<RevisionRecord>,
  42. ) -> Result<(), Self::Error>;
  43. }