doc_table.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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(crate) id: String,
  7. pub(crate) data: String,
  8. pub(crate) 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: String,
  24. }
  25. impl DocTableChangeset {
  26. pub(crate) fn new(params: UpdateDocParams) -> Self {
  27. Self {
  28. id: params.doc_id,
  29. data: params.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. rev_id: self.revision,
  39. }
  40. }
  41. }
  42. impl std::convert::From<Doc> for DocTable {
  43. fn from(doc: Doc) -> Self {
  44. Self {
  45. id: doc.id,
  46. data: doc.data,
  47. revision: doc.rev_id,
  48. }
  49. }
  50. }