doc_table.rs 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. use crate::entities::doc::{Doc, UpdateDocParams};
  2. use flowy_database::schema::doc_table;
  3. #[derive(PartialEq, Clone, Debug, Queryable, Identifiable, Insertable, Associations)]
  4. #[table_name = "doc_table"]
  5. pub(crate) struct DocTable {
  6. pub id: String,
  7. pub data: Vec<u8>,
  8. pub revision: i64,
  9. }
  10. impl DocTable {
  11. pub fn new(doc: Doc) -> Self {
  12. Self {
  13. id: doc.id,
  14. data: doc.data,
  15. revision: 0,
  16. }
  17. }
  18. }
  19. #[derive(AsChangeset, Identifiable, Default, Debug)]
  20. #[table_name = "doc_table"]
  21. pub(crate) struct DocTableChangeset {
  22. pub id: String,
  23. pub data: Vec<u8>,
  24. }
  25. impl DocTableChangeset {
  26. pub(crate) fn new(params: UpdateDocParams) -> Self {
  27. Self {
  28. id: params.id,
  29. data: params.doc_data,
  30. }
  31. }
  32. }
  33. impl std::convert::Into<Doc> for DocTable {
  34. fn into(self) -> Doc {
  35. Doc {
  36. id: self.id,
  37. data: self.data,
  38. revision: self.revision,
  39. }
  40. }
  41. }