nostr_event_head.rs (3658B)
1 use radroots_types::types::{IResult, IResultList}; 2 use serde::{Deserialize, Serialize}; 3 use serde_json::Value; 4 5 #[derive(Serialize, Deserialize)] 6 pub struct NostrEventHead { 7 pub id: String, 8 pub created_at: String, 9 pub updated_at: String, 10 pub key: String, 11 pub kind: u32, 12 pub pubkey: String, 13 pub d_tag: String, 14 pub last_event_id: String, 15 pub last_created_at: u32, 16 pub content_hash: String, 17 } 18 19 #[derive(Clone, Deserialize, Serialize)] 20 pub struct INostrEventHeadFields { 21 pub key: String, 22 pub kind: u32, 23 pub pubkey: String, 24 pub d_tag: String, 25 pub last_event_id: String, 26 pub last_created_at: u32, 27 pub content_hash: String, 28 } 29 30 #[derive(Clone, Deserialize, Serialize)] 31 pub struct INostrEventHeadFieldsPartial { 32 pub key: Option<serde_json::Value>, 33 pub kind: Option<serde_json::Value>, 34 pub pubkey: Option<serde_json::Value>, 35 pub d_tag: Option<serde_json::Value>, 36 pub last_event_id: Option<serde_json::Value>, 37 pub last_created_at: Option<serde_json::Value>, 38 pub content_hash: Option<serde_json::Value>, 39 } 40 41 #[derive(Clone, Deserialize, Serialize)] 42 pub struct INostrEventHeadFieldsFilter { 43 pub id: Option<String>, 44 pub created_at: Option<String>, 45 pub updated_at: Option<String>, 46 pub key: Option<String>, 47 pub kind: Option<u32>, 48 pub pubkey: Option<String>, 49 pub d_tag: Option<String>, 50 pub last_event_id: Option<String>, 51 pub last_created_at: Option<u32>, 52 pub content_hash: Option<String>, 53 } 54 55 #[derive(Clone, Deserialize, Serialize)] 56 #[serde(untagged)] 57 pub enum NostrEventHeadQueryBindValues { 58 Id { id: String }, 59 Key { key: String }, 60 } 61 impl NostrEventHeadQueryBindValues { 62 pub fn to_filter_param(&self) -> (&'static str, Value) { 63 match self { 64 Self::Id { id } => ("id", Value::from(id.clone())), 65 Self::Key { key } => ("key", Value::from(key.clone())), 66 } 67 } 68 69 pub fn primary_key(&self) -> Option<String> { 70 match self { 71 Self::Id { id } => Some(id.clone()), 72 _ => None, 73 } 74 } 75 76 pub fn lookup_key(&self) -> String { 77 match self { 78 Self::Id { id } => id.clone(), 79 Self::Key { key } => key.clone(), 80 } 81 } 82 } 83 84 pub struct INostrEventHeadCreateTs; 85 pub type INostrEventHeadCreate = INostrEventHeadFields; 86 pub struct INostrEventHeadCreateResolveTs; 87 pub type INostrEventHeadCreateResolve = IResult<NostrEventHead>; 88 #[derive(Deserialize, Serialize)] 89 pub struct INostrEventHeadFindOneArgs { 90 pub on: NostrEventHeadQueryBindValues, 91 } 92 93 #[derive(Deserialize, Serialize)] 94 #[serde(untagged)] 95 pub enum INostrEventHeadFindOne { 96 On(INostrEventHeadFindOneArgs), 97 } 98 99 pub struct INostrEventHeadFindOneResolveTs; 100 pub type INostrEventHeadFindOneResolve = IResult<Option<NostrEventHead>>; 101 #[derive(Deserialize, Serialize)] 102 pub struct INostrEventHeadFindManyArgs { 103 pub filter: Option<INostrEventHeadFieldsFilter>, 104 } 105 pub type INostrEventHeadFindMany = INostrEventHeadFindManyArgs; 106 pub struct INostrEventHeadFindManyResolveTs; 107 pub type INostrEventHeadFindManyResolve = IResultList<NostrEventHead>; 108 pub struct INostrEventHeadDeleteTs; 109 pub type INostrEventHeadDelete = INostrEventHeadFindOne; 110 pub struct INostrEventHeadDeleteResolveTs; 111 pub type INostrEventHeadDeleteResolve = IResult<String>; 112 #[derive(Deserialize, Serialize)] 113 pub struct INostrEventHeadUpdateArgs { 114 pub on: NostrEventHeadQueryBindValues, 115 pub fields: INostrEventHeadFieldsPartial, 116 } 117 pub type INostrEventHeadUpdate = INostrEventHeadUpdateArgs; 118 pub struct INostrEventHeadUpdateResolveTs; 119 pub type INostrEventHeadUpdateResolve = IResult<NostrEventHead>;