1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- use crate::entities::doc::{Doc, UpdateDocParams};
- use flowy_database::schema::doc_table;
- #[derive(PartialEq, Clone, Debug, Queryable, Identifiable, Insertable, Associations)]
- #[table_name = "doc_table"]
- pub(crate) struct DocTable {
- pub(crate) id: String,
- pub(crate) data: String,
- pub(crate) revision: i64,
- }
- impl DocTable {
- pub fn new(doc: Doc) -> Self {
- Self {
- id: doc.id,
- data: doc.data,
- revision: 0,
- }
- }
- }
- #[derive(AsChangeset, Identifiable, Default, Debug)]
- #[table_name = "doc_table"]
- pub(crate) struct DocTableChangeset {
- pub id: String,
- pub data: String,
- }
- impl DocTableChangeset {
- pub(crate) fn new(params: UpdateDocParams) -> Self {
- Self {
- id: params.doc_id,
- data: params.data,
- }
- }
- }
- impl std::convert::Into<Doc> for DocTable {
- fn into(self) -> Doc {
- Doc {
- id: self.id,
- data: self.data,
- rev_id: self.revision,
- }
- }
- }
- impl std::convert::From<Doc> for DocTable {
- fn from(doc: Doc) -> Self {
- Self {
- id: doc.id,
- data: doc.data,
- revision: doc.rev_id,
- }
- }
- }
|