lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

commit c6a2c434c43a1a2ef1742e81751915e2318a163c
parent 92a2493e46b5679ff705a1d7e542a060ec42405f
Author: triesap <tyson@radroots.org>
Date:   Tue, 18 Nov 2025 02:12:55 +0000

workspace: refine schema and query layer with typed result operations

Diffstat:
Mtangle-schema/bindings/ts/src/types.ts | 42+++++++++++++++++++++++++++++-------------
Mtangle-schema/src/models/farm.rs | 21+++------------------
Mtangle-schema/src/models/location_gcs.rs | 51+++++++++++++++++++++++++++++++--------------------
Mtangle-schema/src/models/log_error.rs | 21+++------------------
Mtangle-schema/src/models/media_image.rs | 47+++++++++++++++++++++++++++--------------------
Mtangle-schema/src/models/nostr_profile.rs | 52+++++++++++++++++++++++++++++-----------------------
Mtangle-schema/src/models/nostr_relay.rs | 47+++++++++++++++++++++++++++--------------------
Mtangle-schema/src/models/trade_product.rs | 21+++------------------
Mtangle-sql/migrations/0005_nostr_profile.up.sql | 2+-
Mtangle-sql/src/models/farm.rs | 19++++++++++++++-----
Mtangle-sql/src/models/location_gcs.rs | 55++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mtangle-sql/src/models/log_error.rs | 19++++++++++++++-----
Mtangle-sql/src/models/media_image.rs | 45++++++++++++++++++++++++++++++++++++++++-----
Mtangle-sql/src/models/nostr_profile.rs | 45++++++++++++++++++++++++++++++++++++++++-----
Mtangle-sql/src/models/nostr_relay.rs | 45++++++++++++++++++++++++++++++++++++++++-----
Mtangle-sql/src/models/trade_product.rs | 19++++++++++++++-----
16 files changed, 365 insertions(+), 186 deletions(-)

diff --git a/tangle-schema/bindings/ts/src/types.ts b/tangle-schema/bindings/ts/src/types.ts @@ -26,7 +26,7 @@ export type IFarmFindManyResolve = IResultList<Farm>; export type IFarmFindOne = { on: FarmQueryBindValues, }; -export type IFarmFindOneResolve = IResult<Farm | undefined>; +export type IFarmFindOneResolve = IResult<Farm>; export type IFarmLocationRelation = { farm: FarmQueryBindValues, location_gcs: LocationGcsQueryBindValues, }; @@ -50,13 +50,13 @@ export type ILocationGcsFieldsFilter = { id?: string, created_at?: string, updat export type ILocationGcsFieldsPartial = { lat?: number | null, lng?: number | null, geohash?: string | null, tag_0?: string | null, label?: string | null, area?: number | null, elevation?: number | null, soil?: string | null, climate?: string | null, gc_id?: string | null, gc_name?: string | null, gc_admin1_id?: string | null, gc_admin1_name?: string | null, gc_country_id?: string | null, gc_country_name?: string | null, }; -export type ILocationGcsFindMany = { filter: ILocationGcsFieldsFilter | null, }; +export type ILocationGcsFindMany = { filter: ILocationGcsFieldsFilter | null, } | { rel: LocationGcsFindManyRel, }; export type ILocationGcsFindManyResolve = IResultList<LocationGcs>; export type ILocationGcsFindOne = { on: LocationGcsQueryBindValues, }; -export type ILocationGcsFindOneResolve = IResult<LocationGcs | undefined>; +export type ILocationGcsFindOneResolve = IResult<LocationGcs>; export type ILocationGcsUpdate = { on: LocationGcsQueryBindValues, fields: ILocationGcsFieldsPartial, }; @@ -82,7 +82,7 @@ export type ILogErrorFindManyResolve = IResultList<LogError>; export type ILogErrorFindOne = { on: LogErrorQueryBindValues, }; -export type ILogErrorFindOneResolve = IResult<LogError | undefined>; +export type ILogErrorFindOneResolve = IResult<LogError>; export type ILogErrorUpdate = { on: LogErrorQueryBindValues, fields: ILogErrorFieldsPartial, }; @@ -102,13 +102,13 @@ export type IMediaImageFieldsFilter = { id?: string, created_at?: string, update export type IMediaImageFieldsPartial = { file_path?: string | null, mime_type?: string | null, res_base?: string | null, res_path?: string | null, label?: string | null, description?: string | null, }; -export type IMediaImageFindMany = { filter: IMediaImageFieldsFilter | null, }; +export type IMediaImageFindMany = { filter: IMediaImageFieldsFilter | null, } | { rel: MediaImageFindManyRel, }; export type IMediaImageFindManyResolve = IResultList<MediaImage>; export type IMediaImageFindOne = { on: MediaImageQueryBindValues, }; -export type IMediaImageFindOneResolve = IResult<MediaImage | undefined>; +export type IMediaImageFindOneResolve = IResult<MediaImage>; export type IMediaImageUpdate = { on: MediaImageQueryBindValues, fields: IMediaImageFieldsPartial, }; @@ -122,19 +122,19 @@ export type INostrProfileDelete = INostrProfileFindOne; export type INostrProfileDeleteResolve = IResult<string>; -export type INostrProfileFields = { public_key: string, name?: string | null, display_name?: string | null, about?: string | null, website?: string | null, picture?: string | null, banner?: string | null, nip05?: string | null, lud06?: string | null, lud16?: string | null, }; +export type INostrProfileFields = { public_key: string, name: string, display_name?: string | null, about?: string | null, website?: string | null, picture?: string | null, banner?: string | null, nip05?: string | null, lud06?: string | null, lud16?: string | null, }; export type INostrProfileFieldsFilter = { id?: string, created_at?: string, updated_at?: string, public_key?: string, name?: string, display_name?: string, about?: string, website?: string, picture?: string, banner?: string, nip05?: string, lud06?: string, lud16?: string, }; export type INostrProfileFieldsPartial = { public_key?: string | null, name?: string | null, display_name?: string | null, about?: string | null, website?: string | null, picture?: string | null, banner?: string | null, nip05?: string | null, lud06?: string | null, lud16?: string | null, }; -export type INostrProfileFindMany = { filter: INostrProfileFieldsFilter | null, }; +export type INostrProfileFindMany = { filter: INostrProfileFieldsFilter | null, } | { rel: NostrProfileFindManyRel, }; export type INostrProfileFindManyResolve = IResultList<NostrProfile>; export type INostrProfileFindOne = { on: NostrProfileQueryBindValues, }; -export type INostrProfileFindOneResolve = IResult<NostrProfile | undefined>; +export type INostrProfileFindOneResolve = IResult<NostrProfile>; export type INostrProfileRelayRelation = { nostr_profile: NostrProfileQueryBindValues, nostr_relay: NostrRelayQueryBindValues, }; @@ -158,13 +158,13 @@ export type INostrRelayFieldsFilter = { id?: string, created_at?: string, update export type INostrRelayFieldsPartial = { url?: string | null, relay_id?: string | null, name?: string | null, description?: string | null, pubkey?: string | null, contact?: string | null, supported_nips?: string | null, software?: string | null, version?: string | null, data?: string | null, }; -export type INostrRelayFindMany = { filter: INostrRelayFieldsFilter | null, }; +export type INostrRelayFindMany = { filter: INostrRelayFieldsFilter | null, } | { rel: NostrRelayFindManyRel, }; export type INostrRelayFindManyResolve = IResultList<NostrRelay>; export type INostrRelayFindOne = { on: NostrRelayQueryBindValues, }; -export type INostrRelayFindOneResolve = IResult<NostrRelay | undefined>; +export type INostrRelayFindOneResolve = IResult<NostrRelay>; export type INostrRelayUpdate = { on: NostrRelayQueryBindValues, fields: INostrRelayFieldsPartial, }; @@ -190,7 +190,7 @@ export type ITradeProductFindManyResolve = IResultList<TradeProduct>; export type ITradeProductFindOne = { on: TradeProductQueryBindValues, }; -export type ITradeProductFindOneResolve = IResult<TradeProduct | undefined>; +export type ITradeProductFindOneResolve = IResult<TradeProduct>; export type ITradeProductLocationRelation = { trade_product: TradeProductQueryBindValues, location_gcs: LocationGcsQueryBindValues, }; @@ -206,22 +206,38 @@ export type ITradeProductUpdateResolve = IResult<TradeProduct>; export type LocationGcs = { id: string, created_at: string, updated_at: string, lat: number, lng: number, geohash: string, tag_0: string | null, label: string | null, area: number | null, elevation: number | null, soil: string | null, climate: string | null, gc_id: string | null, gc_name: string | null, gc_admin1_id: string | null, gc_admin1_name: string | null, gc_country_id: string | null, gc_country_name: string | null, }; +export type LocationGcsFindManyRel = { "on_trade_product": LocationGcsTradeProductArgs } | { "off_trade_product": LocationGcsTradeProductArgs } | { "on_farm": LocationGcsTradeProductArgs } | { "off_farm": LocationGcsTradeProductArgs }; + export type LocationGcsQueryBindValues = { id: string, } | { geohash: string, }; +export type LocationGcsTradeProductArgs = { id: string, }; + export type LogError = { id: string, created_at: string, updated_at: string, error: string, message: string, stack_trace: string | null, cause: string | null, app_system: string, app_version: string, nostr_pubkey: string, data: string | null, }; export type LogErrorQueryBindValues = { id: string, } | { nostr_pubkey: string, }; export type MediaImage = { id: string, created_at: string, updated_at: string, file_path: string, mime_type: string, res_base: string, res_path: string, label: string | null, description: string | null, }; +export type MediaImageFindManyRel = { "on_trade_product": MediaImageTradeProductArgs } | { "off_trade_product": MediaImageTradeProductArgs }; + export type MediaImageQueryBindValues = { id: string, } | { file_path: string, }; -export type NostrProfile = { id: string, created_at: string, updated_at: string, public_key: string, name: string | null, display_name: string | null, about: string | null, website: string | null, picture: string | null, banner: string | null, nip05: string | null, lud06: string | null, lud16: string | null, }; +export type MediaImageTradeProductArgs = { id: string, }; + +export type NostrProfile = { id: string, created_at: string, updated_at: string, public_key: string, name: string, display_name: string | null, about: string | null, website: string | null, picture: string | null, banner: string | null, nip05: string | null, lud06: string | null, lud16: string | null, }; + +export type NostrProfileFindManyRel = { "on_relay": NostrProfileRelayArgs } | { "off_relay": NostrProfileRelayArgs }; export type NostrProfileQueryBindValues = { id: string, } | { public_key: string, }; +export type NostrProfileRelayArgs = { id: string, }; + export type NostrRelay = { id: string, created_at: string, updated_at: string, url: string, relay_id: string | null, name: string | null, description: string | null, pubkey: string | null, contact: string | null, supported_nips: string | null, software: string | null, version: string | null, data: string | null, }; +export type NostrRelayFindManyRel = { "on_profile": NostrRelayProfileArgs } | { "off_profile": NostrRelayProfileArgs }; + +export type NostrRelayProfileArgs = { public_key: string, }; + export type NostrRelayQueryBindValues = { id: string, } | { url: string, }; export type TradeProduct = { id: string, created_at: string, updated_at: string, key: string, category: string, title: string, summary: string, process: string, lot: string, profile: string, year: bigint, qty_amt: bigint, qty_unit: string, qty_label: string | null, qty_avail: bigint | null, price_amt: number, price_currency: string, price_qty_amt: number, price_qty_unit: string, notes: string | null, }; diff --git a/tangle-schema/src/models/farm.rs b/tangle-schema/src/models/farm.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; #[cfg(feature = "ts-rs")] use ts_rs::TS; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Serialize, Deserialize)] @@ -17,7 +16,6 @@ pub struct Farm { pub title: Option<String>, pub description: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -32,7 +30,6 @@ pub struct IFarmFields { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub description: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -48,7 +45,6 @@ pub struct IFarmFieldsPartial { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub description: Option<serde_json::Value>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -70,7 +66,6 @@ pub struct IFarmFieldsFilter { #[cfg_attr(feature = "ts-rs", ts(optional))] pub description: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -78,7 +73,6 @@ pub struct IFarmFieldsFilter { pub enum FarmQueryBindValues { Id { id: String }, } - impl FarmQueryBindValues { pub fn to_filter_param(&self) -> (&'static str, Value) { match self { @@ -98,7 +92,6 @@ impl FarmQueryBindValues { } } } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -111,7 +104,6 @@ impl FarmQueryBindValues { )] pub struct IFarmCreateTs; pub type IFarmCreate = IFarmFields; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -124,7 +116,6 @@ pub type IFarmCreate = IFarmFields; )] pub struct IFarmCreateResolveTs; pub type IFarmCreateResolve = IResult<Farm>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -135,7 +126,6 @@ pub struct IFarmFindOneArgs { pub on: FarmQueryBindValues, } pub type IFarmFindOne = IFarmFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -143,12 +133,11 @@ pub type IFarmFindOne = IFarmFindOneArgs; export, export_to = "types.ts", rename = "IFarmFindOneResolve", - type = "IResult<Farm | undefined>" + type = "IResult<Farm>" ) )] pub struct IFarmFindOneResolveTs; pub type IFarmFindOneResolve = IResult<Option<Farm>>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -159,7 +148,6 @@ pub struct IFarmFindManyArgs { pub filter: Option<IFarmFieldsFilter>, } pub type IFarmFindMany = IFarmFindManyArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -172,7 +160,6 @@ pub type IFarmFindMany = IFarmFindManyArgs; )] pub struct IFarmFindManyResolveTs; pub type IFarmFindManyResolve = IResultList<Farm>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -185,7 +172,6 @@ pub type IFarmFindManyResolve = IResultList<Farm>; )] pub struct IFarmDeleteTs; pub type IFarmDelete = IFarmFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -198,7 +184,6 @@ pub type IFarmDelete = IFarmFindOneArgs; )] pub struct IFarmDeleteResolveTs; pub type IFarmDeleteResolve = IResult<String>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -210,7 +195,6 @@ pub struct IFarmUpdateArgs { pub fields: IFarmFieldsPartial, } pub type IFarmUpdate = IFarmUpdateArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -222,4 +206,4 @@ pub type IFarmUpdate = IFarmUpdateArgs; ) )] pub struct IFarmUpdateResolveTs; -pub type IFarmUpdateResolve = IResult<Farm>; +pub type IFarmUpdateResolve = IResult<Farm>; +\ No newline at end of file diff --git a/tangle-schema/src/models/location_gcs.rs b/tangle-schema/src/models/location_gcs.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; #[cfg(feature = "ts-rs")] use ts_rs::TS; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Serialize, Deserialize)] @@ -27,7 +26,6 @@ pub struct LocationGcs { pub gc_country_id: Option<String>, pub gc_country_name: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -60,7 +58,6 @@ pub struct ILocationGcsFields { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub gc_country_name: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -96,7 +93,6 @@ pub struct ILocationGcsFieldsPartial { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub gc_country_name: Option<serde_json::Value>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -138,7 +134,6 @@ pub struct ILocationGcsFieldsFilter { #[cfg_attr(feature = "ts-rs", ts(optional))] pub gc_country_name: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -147,7 +142,6 @@ pub enum LocationGcsQueryBindValues { Id { id: String }, Geohash { geohash: String }, } - impl LocationGcsQueryBindValues { pub fn to_filter_param(&self) -> (&'static str, Value) { match self { @@ -170,6 +164,26 @@ impl LocationGcsQueryBindValues { } } } +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub struct LocationGcsTradeProductArgs { + pub id: String, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub enum LocationGcsFindManyRel { + #[serde(rename = "on_trade_product")] + OnTradeProduct(LocationGcsTradeProductArgs), + #[serde(rename = "off_trade_product")] + OffTradeProduct(LocationGcsTradeProductArgs), + #[serde(rename = "on_farm")] + OnFarm(LocationGcsTradeProductArgs), + #[serde(rename = "off_farm")] + OffFarm(LocationGcsTradeProductArgs), +} #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( @@ -183,7 +197,6 @@ impl LocationGcsQueryBindValues { )] pub struct ILocationGcsCreateTs; pub type ILocationGcsCreate = ILocationGcsFields; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -196,7 +209,6 @@ pub type ILocationGcsCreate = ILocationGcsFields; )] pub struct ILocationGcsCreateResolveTs; pub type ILocationGcsCreateResolve = IResult<LocationGcs>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -207,7 +219,6 @@ pub struct ILocationGcsFindOneArgs { pub on: LocationGcsQueryBindValues, } pub type ILocationGcsFindOne = ILocationGcsFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -215,23 +226,26 @@ pub type ILocationGcsFindOne = ILocationGcsFindOneArgs; export, export_to = "types.ts", rename = "ILocationGcsFindOneResolve", - type = "IResult<LocationGcs | undefined>" + type = "IResult<LocationGcs>" ) )] pub struct ILocationGcsFindOneResolveTs; pub type ILocationGcsFindOneResolve = IResult<Option<LocationGcs>>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", ts(export, export_to = "types.ts", rename = "ILocationGcsFindMany") )] #[derive(Deserialize, Serialize)] -pub struct ILocationGcsFindManyArgs { - pub filter: Option<ILocationGcsFieldsFilter>, +#[serde(untagged)] +pub enum ILocationGcsFindMany { + Filter { + filter: Option<ILocationGcsFieldsFilter>, + }, + Rel { + rel: LocationGcsFindManyRel, + }, } -pub type ILocationGcsFindMany = ILocationGcsFindManyArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -244,7 +258,6 @@ pub type ILocationGcsFindMany = ILocationGcsFindManyArgs; )] pub struct ILocationGcsFindManyResolveTs; pub type ILocationGcsFindManyResolve = IResultList<LocationGcs>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -257,7 +270,6 @@ pub type ILocationGcsFindManyResolve = IResultList<LocationGcs>; )] pub struct ILocationGcsDeleteTs; pub type ILocationGcsDelete = ILocationGcsFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -270,7 +282,6 @@ pub type ILocationGcsDelete = ILocationGcsFindOneArgs; )] pub struct ILocationGcsDeleteResolveTs; pub type ILocationGcsDeleteResolve = IResult<String>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -282,7 +293,6 @@ pub struct ILocationGcsUpdateArgs { pub fields: ILocationGcsFieldsPartial, } pub type ILocationGcsUpdate = ILocationGcsUpdateArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -294,4 +304,4 @@ pub type ILocationGcsUpdate = ILocationGcsUpdateArgs; ) )] pub struct ILocationGcsUpdateResolveTs; -pub type ILocationGcsUpdateResolve = IResult<LocationGcs>; +pub type ILocationGcsUpdateResolve = IResult<LocationGcs>; +\ No newline at end of file diff --git a/tangle-schema/src/models/log_error.rs b/tangle-schema/src/models/log_error.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; #[cfg(feature = "ts-rs")] use ts_rs::TS; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Serialize, Deserialize)] @@ -20,7 +19,6 @@ pub struct LogError { pub nostr_pubkey: String, pub data: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -37,7 +35,6 @@ pub struct ILogErrorFields { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub data: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -59,7 +56,6 @@ pub struct ILogErrorFieldsPartial { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub data: Option<serde_json::Value>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -87,7 +83,6 @@ pub struct ILogErrorFieldsFilter { #[cfg_attr(feature = "ts-rs", ts(optional))] pub data: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -96,7 +91,6 @@ pub enum LogErrorQueryBindValues { Id { id: String }, NostrPubkey { nostr_pubkey: String }, } - impl LogErrorQueryBindValues { pub fn to_filter_param(&self) -> (&'static str, Value) { match self { @@ -119,7 +113,6 @@ impl LogErrorQueryBindValues { } } } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -132,7 +125,6 @@ impl LogErrorQueryBindValues { )] pub struct ILogErrorCreateTs; pub type ILogErrorCreate = ILogErrorFields; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -145,7 +137,6 @@ pub type ILogErrorCreate = ILogErrorFields; )] pub struct ILogErrorCreateResolveTs; pub type ILogErrorCreateResolve = IResult<LogError>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -156,7 +147,6 @@ pub struct ILogErrorFindOneArgs { pub on: LogErrorQueryBindValues, } pub type ILogErrorFindOne = ILogErrorFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -164,12 +154,11 @@ pub type ILogErrorFindOne = ILogErrorFindOneArgs; export, export_to = "types.ts", rename = "ILogErrorFindOneResolve", - type = "IResult<LogError | undefined>" + type = "IResult<LogError>" ) )] pub struct ILogErrorFindOneResolveTs; pub type ILogErrorFindOneResolve = IResult<Option<LogError>>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -180,7 +169,6 @@ pub struct ILogErrorFindManyArgs { pub filter: Option<ILogErrorFieldsFilter>, } pub type ILogErrorFindMany = ILogErrorFindManyArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -193,7 +181,6 @@ pub type ILogErrorFindMany = ILogErrorFindManyArgs; )] pub struct ILogErrorFindManyResolveTs; pub type ILogErrorFindManyResolve = IResultList<LogError>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -206,7 +193,6 @@ pub type ILogErrorFindManyResolve = IResultList<LogError>; )] pub struct ILogErrorDeleteTs; pub type ILogErrorDelete = ILogErrorFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -219,7 +205,6 @@ pub type ILogErrorDelete = ILogErrorFindOneArgs; )] pub struct ILogErrorDeleteResolveTs; pub type ILogErrorDeleteResolve = IResult<String>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -231,7 +216,6 @@ pub struct ILogErrorUpdateArgs { pub fields: ILogErrorFieldsPartial, } pub type ILogErrorUpdate = ILogErrorUpdateArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -243,4 +227,4 @@ pub type ILogErrorUpdate = ILogErrorUpdateArgs; ) )] pub struct ILogErrorUpdateResolveTs; -pub type ILogErrorUpdateResolve = IResult<LogError>; +pub type ILogErrorUpdateResolve = IResult<LogError>; +\ No newline at end of file diff --git a/tangle-schema/src/models/media_image.rs b/tangle-schema/src/models/media_image.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; #[cfg(feature = "ts-rs")] use ts_rs::TS; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Serialize, Deserialize)] @@ -18,7 +17,6 @@ pub struct MediaImage { pub label: Option<String>, pub description: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -32,7 +30,6 @@ pub struct IMediaImageFields { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub description: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -50,7 +47,6 @@ pub struct IMediaImageFieldsPartial { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub description: Option<serde_json::Value>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -74,7 +70,6 @@ pub struct IMediaImageFieldsFilter { #[cfg_attr(feature = "ts-rs", ts(optional))] pub description: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -83,7 +78,6 @@ pub enum MediaImageQueryBindValues { Id { id: String }, FilePath { file_path: String }, } - impl MediaImageQueryBindValues { pub fn to_filter_param(&self) -> (&'static str, Value) { match self { @@ -106,6 +100,22 @@ impl MediaImageQueryBindValues { } } } +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub struct MediaImageTradeProductArgs { + pub id: String, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub enum MediaImageFindManyRel { + #[serde(rename = "on_trade_product")] + OnTradeProduct(MediaImageTradeProductArgs), + #[serde(rename = "off_trade_product")] + OffTradeProduct(MediaImageTradeProductArgs), +} #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( @@ -119,7 +129,6 @@ impl MediaImageQueryBindValues { )] pub struct IMediaImageCreateTs; pub type IMediaImageCreate = IMediaImageFields; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -132,7 +141,6 @@ pub type IMediaImageCreate = IMediaImageFields; )] pub struct IMediaImageCreateResolveTs; pub type IMediaImageCreateResolve = IResult<MediaImage>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -143,7 +151,6 @@ pub struct IMediaImageFindOneArgs { pub on: MediaImageQueryBindValues, } pub type IMediaImageFindOne = IMediaImageFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -151,23 +158,26 @@ pub type IMediaImageFindOne = IMediaImageFindOneArgs; export, export_to = "types.ts", rename = "IMediaImageFindOneResolve", - type = "IResult<MediaImage | undefined>" + type = "IResult<MediaImage>" ) )] pub struct IMediaImageFindOneResolveTs; pub type IMediaImageFindOneResolve = IResult<Option<MediaImage>>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", ts(export, export_to = "types.ts", rename = "IMediaImageFindMany") )] #[derive(Deserialize, Serialize)] -pub struct IMediaImageFindManyArgs { - pub filter: Option<IMediaImageFieldsFilter>, +#[serde(untagged)] +pub enum IMediaImageFindMany { + Filter { + filter: Option<IMediaImageFieldsFilter>, + }, + Rel { + rel: MediaImageFindManyRel, + }, } -pub type IMediaImageFindMany = IMediaImageFindManyArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -180,7 +190,6 @@ pub type IMediaImageFindMany = IMediaImageFindManyArgs; )] pub struct IMediaImageFindManyResolveTs; pub type IMediaImageFindManyResolve = IResultList<MediaImage>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -193,7 +202,6 @@ pub type IMediaImageFindManyResolve = IResultList<MediaImage>; )] pub struct IMediaImageDeleteTs; pub type IMediaImageDelete = IMediaImageFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -206,7 +214,6 @@ pub type IMediaImageDelete = IMediaImageFindOneArgs; )] pub struct IMediaImageDeleteResolveTs; pub type IMediaImageDeleteResolve = IResult<String>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -218,7 +225,6 @@ pub struct IMediaImageUpdateArgs { pub fields: IMediaImageFieldsPartial, } pub type IMediaImageUpdate = IMediaImageUpdateArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -230,4 +236,4 @@ pub type IMediaImageUpdate = IMediaImageUpdateArgs; ) )] pub struct IMediaImageUpdateResolveTs; -pub type IMediaImageUpdateResolve = IResult<MediaImage>; +pub type IMediaImageUpdateResolve = IResult<MediaImage>; +\ No newline at end of file diff --git a/tangle-schema/src/models/nostr_profile.rs b/tangle-schema/src/models/nostr_profile.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; #[cfg(feature = "ts-rs")] use ts_rs::TS; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Serialize, Deserialize)] @@ -12,7 +11,7 @@ pub struct NostrProfile { pub created_at: String, pub updated_at: String, pub public_key: String, - pub name: Option<String>, + pub name: String, pub display_name: Option<String>, pub about: Option<String>, pub website: Option<String>, @@ -22,14 +21,12 @@ pub struct NostrProfile { pub lud06: Option<String>, pub lud16: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] pub struct INostrProfileFields { pub public_key: String, - #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] - pub name: Option<String>, + pub name: String, #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub display_name: Option<String>, #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] @@ -47,7 +44,6 @@ pub struct INostrProfileFields { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub lud16: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -73,7 +69,6 @@ pub struct INostrProfileFieldsPartial { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub lud16: Option<serde_json::Value>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -105,7 +100,6 @@ pub struct INostrProfileFieldsFilter { #[cfg_attr(feature = "ts-rs", ts(optional))] pub lud16: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -114,7 +108,6 @@ pub enum NostrProfileQueryBindValues { Id { id: String }, PublicKey { public_key: String }, } - impl NostrProfileQueryBindValues { pub fn to_filter_param(&self) -> (&'static str, Value) { match self { @@ -137,6 +130,22 @@ impl NostrProfileQueryBindValues { } } } +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub struct NostrProfileRelayArgs { + pub id: String, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub enum NostrProfileFindManyRel { + #[serde(rename = "on_relay")] + OnRelay(NostrProfileRelayArgs), + #[serde(rename = "off_relay")] + OffRelay(NostrProfileRelayArgs), +} #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( @@ -150,7 +159,6 @@ impl NostrProfileQueryBindValues { )] pub struct INostrProfileCreateTs; pub type INostrProfileCreate = INostrProfileFields; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -163,7 +171,6 @@ pub type INostrProfileCreate = INostrProfileFields; )] pub struct INostrProfileCreateResolveTs; pub type INostrProfileCreateResolve = IResult<NostrProfile>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -174,7 +181,6 @@ pub struct INostrProfileFindOneArgs { pub on: NostrProfileQueryBindValues, } pub type INostrProfileFindOne = INostrProfileFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -182,23 +188,26 @@ pub type INostrProfileFindOne = INostrProfileFindOneArgs; export, export_to = "types.ts", rename = "INostrProfileFindOneResolve", - type = "IResult<NostrProfile | undefined>" + type = "IResult<NostrProfile>" ) )] pub struct INostrProfileFindOneResolveTs; pub type INostrProfileFindOneResolve = IResult<Option<NostrProfile>>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", ts(export, export_to = "types.ts", rename = "INostrProfileFindMany") )] #[derive(Deserialize, Serialize)] -pub struct INostrProfileFindManyArgs { - pub filter: Option<INostrProfileFieldsFilter>, +#[serde(untagged)] +pub enum INostrProfileFindMany { + Filter { + filter: Option<INostrProfileFieldsFilter>, + }, + Rel { + rel: NostrProfileFindManyRel, + }, } -pub type INostrProfileFindMany = INostrProfileFindManyArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -211,7 +220,6 @@ pub type INostrProfileFindMany = INostrProfileFindManyArgs; )] pub struct INostrProfileFindManyResolveTs; pub type INostrProfileFindManyResolve = IResultList<NostrProfile>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -224,7 +232,6 @@ pub type INostrProfileFindManyResolve = IResultList<NostrProfile>; )] pub struct INostrProfileDeleteTs; pub type INostrProfileDelete = INostrProfileFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -237,7 +244,6 @@ pub type INostrProfileDelete = INostrProfileFindOneArgs; )] pub struct INostrProfileDeleteResolveTs; pub type INostrProfileDeleteResolve = IResult<String>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -249,7 +255,6 @@ pub struct INostrProfileUpdateArgs { pub fields: INostrProfileFieldsPartial, } pub type INostrProfileUpdate = INostrProfileUpdateArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -261,4 +266,4 @@ pub type INostrProfileUpdate = INostrProfileUpdateArgs; ) )] pub struct INostrProfileUpdateResolveTs; -pub type INostrProfileUpdateResolve = IResult<NostrProfile>; +pub type INostrProfileUpdateResolve = IResult<NostrProfile>; +\ No newline at end of file diff --git a/tangle-schema/src/models/nostr_relay.rs b/tangle-schema/src/models/nostr_relay.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; #[cfg(feature = "ts-rs")] use ts_rs::TS; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Serialize, Deserialize)] @@ -22,7 +21,6 @@ pub struct NostrRelay { pub version: Option<String>, pub data: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -47,7 +45,6 @@ pub struct INostrRelayFields { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub data: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -73,7 +70,6 @@ pub struct INostrRelayFieldsPartial { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub data: Option<serde_json::Value>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -105,7 +101,6 @@ pub struct INostrRelayFieldsFilter { #[cfg_attr(feature = "ts-rs", ts(optional))] pub data: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -114,7 +109,6 @@ pub enum NostrRelayQueryBindValues { Id { id: String }, Url { url: String }, } - impl NostrRelayQueryBindValues { pub fn to_filter_param(&self) -> (&'static str, Value) { match self { @@ -137,6 +131,22 @@ impl NostrRelayQueryBindValues { } } } +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub struct NostrRelayProfileArgs { + pub public_key: String, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Deserialize, Serialize)] +pub enum NostrRelayFindManyRel { + #[serde(rename = "on_profile")] + OnProfile(NostrRelayProfileArgs), + #[serde(rename = "off_profile")] + OffProfile(NostrRelayProfileArgs), +} #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( @@ -150,7 +160,6 @@ impl NostrRelayQueryBindValues { )] pub struct INostrRelayCreateTs; pub type INostrRelayCreate = INostrRelayFields; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -163,7 +172,6 @@ pub type INostrRelayCreate = INostrRelayFields; )] pub struct INostrRelayCreateResolveTs; pub type INostrRelayCreateResolve = IResult<NostrRelay>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -174,7 +182,6 @@ pub struct INostrRelayFindOneArgs { pub on: NostrRelayQueryBindValues, } pub type INostrRelayFindOne = INostrRelayFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -182,23 +189,26 @@ pub type INostrRelayFindOne = INostrRelayFindOneArgs; export, export_to = "types.ts", rename = "INostrRelayFindOneResolve", - type = "IResult<NostrRelay | undefined>" + type = "IResult<NostrRelay>" ) )] pub struct INostrRelayFindOneResolveTs; pub type INostrRelayFindOneResolve = IResult<Option<NostrRelay>>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", ts(export, export_to = "types.ts", rename = "INostrRelayFindMany") )] #[derive(Deserialize, Serialize)] -pub struct INostrRelayFindManyArgs { - pub filter: Option<INostrRelayFieldsFilter>, +#[serde(untagged)] +pub enum INostrRelayFindMany { + Filter { + filter: Option<INostrRelayFieldsFilter>, + }, + Rel { + rel: NostrRelayFindManyRel, + }, } -pub type INostrRelayFindMany = INostrRelayFindManyArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -211,7 +221,6 @@ pub type INostrRelayFindMany = INostrRelayFindManyArgs; )] pub struct INostrRelayFindManyResolveTs; pub type INostrRelayFindManyResolve = IResultList<NostrRelay>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -224,7 +233,6 @@ pub type INostrRelayFindManyResolve = IResultList<NostrRelay>; )] pub struct INostrRelayDeleteTs; pub type INostrRelayDelete = INostrRelayFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -237,7 +245,6 @@ pub type INostrRelayDelete = INostrRelayFindOneArgs; )] pub struct INostrRelayDeleteResolveTs; pub type INostrRelayDeleteResolve = IResult<String>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -249,7 +256,6 @@ pub struct INostrRelayUpdateArgs { pub fields: INostrRelayFieldsPartial, } pub type INostrRelayUpdate = INostrRelayUpdateArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -261,4 +267,4 @@ pub type INostrRelayUpdate = INostrRelayUpdateArgs; ) )] pub struct INostrRelayUpdateResolveTs; -pub type INostrRelayUpdateResolve = IResult<NostrRelay>; +pub type INostrRelayUpdateResolve = IResult<NostrRelay>; +\ No newline at end of file diff --git a/tangle-schema/src/models/trade_product.rs b/tangle-schema/src/models/trade_product.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; #[cfg(feature = "ts-rs")] use ts_rs::TS; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Serialize, Deserialize)] @@ -29,7 +28,6 @@ pub struct TradeProduct { pub price_qty_unit: String, pub notes: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -55,7 +53,6 @@ pub struct ITradeProductFields { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub notes: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -95,7 +92,6 @@ pub struct ITradeProductFieldsPartial { #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub notes: Option<serde_json::Value>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -141,7 +137,6 @@ pub struct ITradeProductFieldsFilter { #[cfg_attr(feature = "ts-rs", ts(optional))] pub notes: Option<String>, } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Deserialize, Serialize)] @@ -149,7 +144,6 @@ pub struct ITradeProductFieldsFilter { pub enum TradeProductQueryBindValues { Id { id: String }, } - impl TradeProductQueryBindValues { pub fn to_filter_param(&self) -> (&'static str, Value) { match self { @@ -169,7 +163,6 @@ impl TradeProductQueryBindValues { } } } - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -182,7 +175,6 @@ impl TradeProductQueryBindValues { )] pub struct ITradeProductCreateTs; pub type ITradeProductCreate = ITradeProductFields; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -195,7 +187,6 @@ pub type ITradeProductCreate = ITradeProductFields; )] pub struct ITradeProductCreateResolveTs; pub type ITradeProductCreateResolve = IResult<TradeProduct>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -206,7 +197,6 @@ pub struct ITradeProductFindOneArgs { pub on: TradeProductQueryBindValues, } pub type ITradeProductFindOne = ITradeProductFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -214,12 +204,11 @@ pub type ITradeProductFindOne = ITradeProductFindOneArgs; export, export_to = "types.ts", rename = "ITradeProductFindOneResolve", - type = "IResult<TradeProduct | undefined>" + type = "IResult<TradeProduct>" ) )] pub struct ITradeProductFindOneResolveTs; pub type ITradeProductFindOneResolve = IResult<Option<TradeProduct>>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -230,7 +219,6 @@ pub struct ITradeProductFindManyArgs { pub filter: Option<ITradeProductFieldsFilter>, } pub type ITradeProductFindMany = ITradeProductFindManyArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -243,7 +231,6 @@ pub type ITradeProductFindMany = ITradeProductFindManyArgs; )] pub struct ITradeProductFindManyResolveTs; pub type ITradeProductFindManyResolve = IResultList<TradeProduct>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -256,7 +243,6 @@ pub type ITradeProductFindManyResolve = IResultList<TradeProduct>; )] pub struct ITradeProductDeleteTs; pub type ITradeProductDelete = ITradeProductFindOneArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -269,7 +255,6 @@ pub type ITradeProductDelete = ITradeProductFindOneArgs; )] pub struct ITradeProductDeleteResolveTs; pub type ITradeProductDeleteResolve = IResult<String>; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -281,7 +266,6 @@ pub struct ITradeProductUpdateArgs { pub fields: ITradeProductFieldsPartial, } pub type ITradeProductUpdate = ITradeProductUpdateArgs; - #[cfg_attr(feature = "ts-rs", derive(TS))] #[cfg_attr( feature = "ts-rs", @@ -293,4 +277,4 @@ pub type ITradeProductUpdate = ITradeProductUpdateArgs; ) )] pub struct ITradeProductUpdateResolveTs; -pub type ITradeProductUpdateResolve = IResult<TradeProduct>; +pub type ITradeProductUpdateResolve = IResult<TradeProduct>; +\ No newline at end of file diff --git a/tangle-sql/migrations/0005_nostr_profile.up.sql b/tangle-sql/migrations/0005_nostr_profile.up.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS nostr_profile ( created_at DATETIME NOT NULL CHECK(length(created_at) = 24), updated_at DATETIME NOT NULL CHECK(length(updated_at) = 24), public_key CHAR(64) NOT NULL CHECK(length(public_key) = 64), - name TEXT, + name TEXT NOT NULL, display_name TEXT, about TEXT, website TEXT, diff --git a/tangle-sql/src/models/farm.rs b/tangle-sql/src/models/farm.rs @@ -1,18 +1,19 @@ use radroots_sql_core::error::SqlError; use radroots_sql_core::{SqlExecutor, utils}; use radroots_tangle_schema::farm::{ - Farm, - FarmQueryBindValues, IFarmCreate, IFarmCreateResolve, IFarmDelete, IFarmDeleteResolve, + IFarmFieldsFilter, IFarmFindMany, IFarmFindManyResolve, IFarmFindOne, IFarmFindOneResolve, IFarmUpdate, IFarmUpdateResolve, + Farm, + FarmQueryBindValues, }; use radroots_types::types::{IError, IResult, IResultList}; use serde_json::Value; @@ -61,11 +62,19 @@ pub fn find_many<E: SqlExecutor>( exec: &E, opts: &IFarmFindMany, ) -> Result<IFarmFindManyResolve, IError<SqlError>> { - let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, opts.filter.as_ref()); + let results = find_many_filter(exec, &opts.filter)?; + Ok(IResultList { results }) +} + +fn find_many_filter<E: SqlExecutor>( + exec: &E, + filter: &Option<IFarmFieldsFilter>, +) -> Result<Vec<Farm>, IError<SqlError>> { + let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, filter.as_ref()); let params_json = utils::to_params_json(bind_values)?; let json = exec.query_raw(&sql, &params_json)?; - let results: Vec<Farm> = utils::parse_json(&json)?; - Ok(IResultList { results }) + let rows: Vec<Farm> = utils::parse_json(&json)?; + Ok(rows) } fn select_by_id<E: SqlExecutor>(exec: &E, id: &str) -> Result<Farm, IError<SqlError>> { diff --git a/tangle-sql/src/models/location_gcs.rs b/tangle-sql/src/models/location_gcs.rs @@ -1,18 +1,20 @@ use radroots_sql_core::error::SqlError; use radroots_sql_core::{SqlExecutor, utils}; use radroots_tangle_schema::location_gcs::{ - LocationGcs, - LocationGcsQueryBindValues, ILocationGcsCreate, ILocationGcsCreateResolve, ILocationGcsDelete, ILocationGcsDeleteResolve, + ILocationGcsFieldsFilter, ILocationGcsFindMany, ILocationGcsFindManyResolve, ILocationGcsFindOne, ILocationGcsFindOneResolve, ILocationGcsUpdate, ILocationGcsUpdateResolve, + LocationGcs, + LocationGcsFindManyRel, + LocationGcsQueryBindValues, }; use radroots_types::types::{IError, IResult, IResultList}; use serde_json::Value; @@ -61,11 +63,54 @@ pub fn find_many<E: SqlExecutor>( exec: &E, opts: &ILocationGcsFindMany, ) -> Result<ILocationGcsFindManyResolve, IError<SqlError>> { - let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, opts.filter.as_ref()); + let results = match opts { + ILocationGcsFindMany::Filter { filter } => find_many_filter(exec, filter)?, + ILocationGcsFindMany::Rel { rel } => find_many_by_rel(exec, rel)?, + }; + Ok(IResultList { results }) +} + +fn find_many_filter<E: SqlExecutor>( + exec: &E, + filter: &Option<ILocationGcsFieldsFilter>, +) -> Result<Vec<LocationGcs>, IError<SqlError>> { + let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, filter.as_ref()); let params_json = utils::to_params_json(bind_values)?; let json = exec.query_raw(&sql, &params_json)?; - let results: Vec<LocationGcs> = utils::parse_json(&json)?; - Ok(IResultList { results }) + let rows: Vec<LocationGcs> = utils::parse_json(&json)?; + Ok(rows) +} + +fn find_many_by_rel<E: SqlExecutor>( + exec: &E, + rel: &LocationGcsFindManyRel, +) -> Result<Vec<LocationGcs>, IError<SqlError>> { + let (sql, bind_values): (String, Vec<Value>) = match rel { + LocationGcsFindManyRel::OnTradeProduct(args) => { + let sql = String::from("SELECT lg.* FROM location_gcs lg JOIN trade_product_location tp_lg ON lg.id = tp_lg.tb_lg WHERE tp_lg.tb_tp = ?;"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + LocationGcsFindManyRel::OffTradeProduct(args) => { + let sql = String::from("SELECT lg.* FROM location_gcs lg WHERE NOT EXISTS (SELECT 1 FROM trade_product_location tp_lg WHERE tp_lg.tb_lg = lg.id AND tp_lg.tb_tp = ?);"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + LocationGcsFindManyRel::OnFarm(args) => { + let sql = String::from("SELECT lg.* FROM location_gcs lg JOIN farm_location farm_lg ON lg.id = farm_lg.tb_lg WHERE farm_lg.tb_farm = ?;"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + LocationGcsFindManyRel::OffFarm(args) => { + let sql = String::from("SELECT lg.* FROM location_gcs lg WHERE NOT EXISTS (SELECT 1 FROM farm_location farm_lg WHERE farm_lg.tb_lg = lg.id AND farm_lg.tb_farm = ?);"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + }; + let params_json = utils::to_params_json(bind_values)?; + let json = exec.query_raw(&sql, &params_json)?; + let rows: Vec<LocationGcs> = utils::parse_json(&json)?; + Ok(rows) } fn select_by_id<E: SqlExecutor>(exec: &E, id: &str) -> Result<LocationGcs, IError<SqlError>> { diff --git a/tangle-sql/src/models/log_error.rs b/tangle-sql/src/models/log_error.rs @@ -1,18 +1,19 @@ use radroots_sql_core::error::SqlError; use radroots_sql_core::{SqlExecutor, utils}; use radroots_tangle_schema::log_error::{ - LogError, - LogErrorQueryBindValues, ILogErrorCreate, ILogErrorCreateResolve, ILogErrorDelete, ILogErrorDeleteResolve, + ILogErrorFieldsFilter, ILogErrorFindMany, ILogErrorFindManyResolve, ILogErrorFindOne, ILogErrorFindOneResolve, ILogErrorUpdate, ILogErrorUpdateResolve, + LogError, + LogErrorQueryBindValues, }; use radroots_types::types::{IError, IResult, IResultList}; use serde_json::Value; @@ -61,11 +62,19 @@ pub fn find_many<E: SqlExecutor>( exec: &E, opts: &ILogErrorFindMany, ) -> Result<ILogErrorFindManyResolve, IError<SqlError>> { - let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, opts.filter.as_ref()); + let results = find_many_filter(exec, &opts.filter)?; + Ok(IResultList { results }) +} + +fn find_many_filter<E: SqlExecutor>( + exec: &E, + filter: &Option<ILogErrorFieldsFilter>, +) -> Result<Vec<LogError>, IError<SqlError>> { + let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, filter.as_ref()); let params_json = utils::to_params_json(bind_values)?; let json = exec.query_raw(&sql, &params_json)?; - let results: Vec<LogError> = utils::parse_json(&json)?; - Ok(IResultList { results }) + let rows: Vec<LogError> = utils::parse_json(&json)?; + Ok(rows) } fn select_by_id<E: SqlExecutor>(exec: &E, id: &str) -> Result<LogError, IError<SqlError>> { diff --git a/tangle-sql/src/models/media_image.rs b/tangle-sql/src/models/media_image.rs @@ -1,18 +1,20 @@ use radroots_sql_core::error::SqlError; use radroots_sql_core::{SqlExecutor, utils}; use radroots_tangle_schema::media_image::{ - MediaImage, - MediaImageQueryBindValues, IMediaImageCreate, IMediaImageCreateResolve, IMediaImageDelete, IMediaImageDeleteResolve, + IMediaImageFieldsFilter, IMediaImageFindMany, IMediaImageFindManyResolve, IMediaImageFindOne, IMediaImageFindOneResolve, IMediaImageUpdate, IMediaImageUpdateResolve, + MediaImage, + MediaImageFindManyRel, + MediaImageQueryBindValues, }; use radroots_types::types::{IError, IResult, IResultList}; use serde_json::Value; @@ -61,11 +63,44 @@ pub fn find_many<E: SqlExecutor>( exec: &E, opts: &IMediaImageFindMany, ) -> Result<IMediaImageFindManyResolve, IError<SqlError>> { - let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, opts.filter.as_ref()); + let results = match opts { + IMediaImageFindMany::Filter { filter } => find_many_filter(exec, filter)?, + IMediaImageFindMany::Rel { rel } => find_many_by_rel(exec, rel)?, + }; + Ok(IResultList { results }) +} + +fn find_many_filter<E: SqlExecutor>( + exec: &E, + filter: &Option<IMediaImageFieldsFilter>, +) -> Result<Vec<MediaImage>, IError<SqlError>> { + let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, filter.as_ref()); let params_json = utils::to_params_json(bind_values)?; let json = exec.query_raw(&sql, &params_json)?; - let results: Vec<MediaImage> = utils::parse_json(&json)?; - Ok(IResultList { results }) + let rows: Vec<MediaImage> = utils::parse_json(&json)?; + Ok(rows) +} + +fn find_many_by_rel<E: SqlExecutor>( + exec: &E, + rel: &MediaImageFindManyRel, +) -> Result<Vec<MediaImage>, IError<SqlError>> { + let (sql, bind_values): (String, Vec<Value>) = match rel { + MediaImageFindManyRel::OnTradeProduct(args) => { + let sql = String::from("SELECT mu.* FROM media_image mu JOIN trade_product_media tp_lg ON mu.id = tp_lg.tb_mu WHERE tp_lg.tb_tp = ?;"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + MediaImageFindManyRel::OffTradeProduct(args) => { + let sql = String::from("SELECT mu.* FROM media_image mu WHERE NOT EXISTS (SELECT 1 FROM trade_product_media tp_lg WHERE tp_lg.tb_mu = mu.id AND tp_lg.tb_tp = ?);"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + }; + let params_json = utils::to_params_json(bind_values)?; + let json = exec.query_raw(&sql, &params_json)?; + let rows: Vec<MediaImage> = utils::parse_json(&json)?; + Ok(rows) } fn select_by_id<E: SqlExecutor>(exec: &E, id: &str) -> Result<MediaImage, IError<SqlError>> { diff --git a/tangle-sql/src/models/nostr_profile.rs b/tangle-sql/src/models/nostr_profile.rs @@ -1,18 +1,20 @@ use radroots_sql_core::error::SqlError; use radroots_sql_core::{SqlExecutor, utils}; use radroots_tangle_schema::nostr_profile::{ - NostrProfile, - NostrProfileQueryBindValues, INostrProfileCreate, INostrProfileCreateResolve, INostrProfileDelete, INostrProfileDeleteResolve, + INostrProfileFieldsFilter, INostrProfileFindMany, INostrProfileFindManyResolve, INostrProfileFindOne, INostrProfileFindOneResolve, INostrProfileUpdate, INostrProfileUpdateResolve, + NostrProfile, + NostrProfileFindManyRel, + NostrProfileQueryBindValues, }; use radroots_types::types::{IError, IResult, IResultList}; use serde_json::Value; @@ -61,11 +63,44 @@ pub fn find_many<E: SqlExecutor>( exec: &E, opts: &INostrProfileFindMany, ) -> Result<INostrProfileFindManyResolve, IError<SqlError>> { - let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, opts.filter.as_ref()); + let results = match opts { + INostrProfileFindMany::Filter { filter } => find_many_filter(exec, filter)?, + INostrProfileFindMany::Rel { rel } => find_many_by_rel(exec, rel)?, + }; + Ok(IResultList { results }) +} + +fn find_many_filter<E: SqlExecutor>( + exec: &E, + filter: &Option<INostrProfileFieldsFilter>, +) -> Result<Vec<NostrProfile>, IError<SqlError>> { + let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, filter.as_ref()); let params_json = utils::to_params_json(bind_values)?; let json = exec.query_raw(&sql, &params_json)?; - let results: Vec<NostrProfile> = utils::parse_json(&json)?; - Ok(IResultList { results }) + let rows: Vec<NostrProfile> = utils::parse_json(&json)?; + Ok(rows) +} + +fn find_many_by_rel<E: SqlExecutor>( + exec: &E, + rel: &NostrProfileFindManyRel, +) -> Result<Vec<NostrProfile>, IError<SqlError>> { + let (sql, bind_values): (String, Vec<Value>) = match rel { + NostrProfileFindManyRel::OnRelay(args) => { + let sql = String::from("SELECT pr.* FROM nostr_profile pr JOIN nostr_profile_relay pr_rl ON pr.id = pr_rl.tb_pr WHERE pr_rl.tb_rl = ?;"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + NostrProfileFindManyRel::OffRelay(args) => { + let sql = String::from("SELECT pr.* FROM nostr_profile pr WHERE NOT EXISTS (SELECT 1 FROM nostr_profile_relay pr_rl WHERE pr_rl.tb_pr = pr.id AND pr_rl.tb_rl = ?);"); + let binds = vec![Value::from(args.id.clone())]; + (sql, binds) + } + }; + let params_json = utils::to_params_json(bind_values)?; + let json = exec.query_raw(&sql, &params_json)?; + let rows: Vec<NostrProfile> = utils::parse_json(&json)?; + Ok(rows) } fn select_by_id<E: SqlExecutor>(exec: &E, id: &str) -> Result<NostrProfile, IError<SqlError>> { diff --git a/tangle-sql/src/models/nostr_relay.rs b/tangle-sql/src/models/nostr_relay.rs @@ -1,18 +1,20 @@ use radroots_sql_core::error::SqlError; use radroots_sql_core::{SqlExecutor, utils}; use radroots_tangle_schema::nostr_relay::{ - NostrRelay, - NostrRelayQueryBindValues, INostrRelayCreate, INostrRelayCreateResolve, INostrRelayDelete, INostrRelayDeleteResolve, + INostrRelayFieldsFilter, INostrRelayFindMany, INostrRelayFindManyResolve, INostrRelayFindOne, INostrRelayFindOneResolve, INostrRelayUpdate, INostrRelayUpdateResolve, + NostrRelay, + NostrRelayFindManyRel, + NostrRelayQueryBindValues, }; use radroots_types::types::{IError, IResult, IResultList}; use serde_json::Value; @@ -61,11 +63,44 @@ pub fn find_many<E: SqlExecutor>( exec: &E, opts: &INostrRelayFindMany, ) -> Result<INostrRelayFindManyResolve, IError<SqlError>> { - let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, opts.filter.as_ref()); + let results = match opts { + INostrRelayFindMany::Filter { filter } => find_many_filter(exec, filter)?, + INostrRelayFindMany::Rel { rel } => find_many_by_rel(exec, rel)?, + }; + Ok(IResultList { results }) +} + +fn find_many_filter<E: SqlExecutor>( + exec: &E, + filter: &Option<INostrRelayFieldsFilter>, +) -> Result<Vec<NostrRelay>, IError<SqlError>> { + let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, filter.as_ref()); let params_json = utils::to_params_json(bind_values)?; let json = exec.query_raw(&sql, &params_json)?; - let results: Vec<NostrRelay> = utils::parse_json(&json)?; - Ok(IResultList { results }) + let rows: Vec<NostrRelay> = utils::parse_json(&json)?; + Ok(rows) +} + +fn find_many_by_rel<E: SqlExecutor>( + exec: &E, + rel: &NostrRelayFindManyRel, +) -> Result<Vec<NostrRelay>, IError<SqlError>> { + let (sql, bind_values): (String, Vec<Value>) = match rel { + NostrRelayFindManyRel::OnProfile(args) => { + let sql = String::from("SELECT rl.* FROM nostr_relay rl JOIN nostr_profile_relay pr_rl ON rl.id = pr_rl.tb_rl JOIN nostr_profile pr ON pr.id = pr_rl.tb_pr WHERE pr.public_key = ?;"); + let binds = vec![Value::from(args.public_key.clone())]; + (sql, binds) + } + NostrRelayFindManyRel::OffProfile(args) => { + let sql = String::from("SELECT rl.* FROM nostr_relay rl LEFT JOIN nostr_profile_relay pr_rl ON rl.id = pr_rl.tb_rl LEFT JOIN nostr_profile pr ON pr.id = pr_rl.tb_pr WHERE pr.public_key <> ?;"); + let binds = vec![Value::from(args.public_key.clone())]; + (sql, binds) + } + }; + let params_json = utils::to_params_json(bind_values)?; + let json = exec.query_raw(&sql, &params_json)?; + let rows: Vec<NostrRelay> = utils::parse_json(&json)?; + Ok(rows) } fn select_by_id<E: SqlExecutor>(exec: &E, id: &str) -> Result<NostrRelay, IError<SqlError>> { diff --git a/tangle-sql/src/models/trade_product.rs b/tangle-sql/src/models/trade_product.rs @@ -1,18 +1,19 @@ use radroots_sql_core::error::SqlError; use radroots_sql_core::{SqlExecutor, utils}; use radroots_tangle_schema::trade_product::{ - TradeProduct, - TradeProductQueryBindValues, ITradeProductCreate, ITradeProductCreateResolve, ITradeProductDelete, ITradeProductDeleteResolve, + ITradeProductFieldsFilter, ITradeProductFindMany, ITradeProductFindManyResolve, ITradeProductFindOne, ITradeProductFindOneResolve, ITradeProductUpdate, ITradeProductUpdateResolve, + TradeProduct, + TradeProductQueryBindValues, }; use radroots_types::types::{IError, IResult, IResultList}; use serde_json::Value; @@ -61,11 +62,19 @@ pub fn find_many<E: SqlExecutor>( exec: &E, opts: &ITradeProductFindMany, ) -> Result<ITradeProductFindManyResolve, IError<SqlError>> { - let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, opts.filter.as_ref()); + let results = find_many_filter(exec, &opts.filter)?; + Ok(IResultList { results }) +} + +fn find_many_filter<E: SqlExecutor>( + exec: &E, + filter: &Option<ITradeProductFieldsFilter>, +) -> Result<Vec<TradeProduct>, IError<SqlError>> { + let (sql, bind_values) = utils::build_select_query_with_meta(TABLE_NAME, filter.as_ref()); let params_json = utils::to_params_json(bind_values)?; let json = exec.query_raw(&sql, &params_json)?; - let results: Vec<TradeProduct> = utils::parse_json(&json)?; - Ok(IResultList { results }) + let rows: Vec<TradeProduct> = utils::parse_json(&json)?; + Ok(rows) } fn select_by_id<E: SqlExecutor>(exec: &E, id: &str) -> Result<TradeProduct, IError<SqlError>> {