@@ -5,7 +5,10 @@ use std::path::Path;
55
66const DEFAULT_SCHEMA : & str = "public" ;
77
8- /// Summary row returned by `GET /databases` (no `default_connection_id`).
8+ /// CLI output shape for `databases list` rows. A curated, stably-ordered view
9+ /// mapped from the SDK's `DatabaseSummary` (see the `From` impl) so the
10+ /// `-o json`/`-o yaml` contract stays decoupled from generated-model field
11+ /// order and nullability.
912#[ derive( Clone , Debug , Deserialize , Serialize , PartialEq , Eq ) ]
1013struct DatabaseSummary {
1114 id : String ,
@@ -15,7 +18,10 @@ struct DatabaseSummary {
1518 default_catalog : Option < String > ,
1619}
1720
18- /// Full record returned by `GET /databases/{id}`.
21+ /// CLI output shape for `databases get`. A curated, stably-ordered view mapped
22+ /// from the SDK's `DatabaseDetailResponse` (see the `From` impl), keeping the
23+ /// `-o json`/`-o yaml` contract independent of the generated model's field order
24+ /// and `Option<Option<_>>` nullability.
1925#[ derive( Clone , Debug , Deserialize , Serialize , PartialEq , Eq ) ]
2026pub struct Database {
2127 pub id : String ,
@@ -88,10 +94,11 @@ struct LoadManagedTableResponse {
8894 arrow_schema_json : String ,
8995}
9096
91- impl Database {
92- /// Map the SDK's typed `DatabaseDetailResponse` into the CLI's `Database`,
93- /// flattening the SDK's `Option<Option<_>>` nullable fields.
94- fn from_detail ( d : hotdata:: models:: DatabaseDetailResponse ) -> Self {
97+ impl From < hotdata:: models:: DatabaseDetailResponse > for Database {
98+ /// Map the SDK's typed detail response into the CLI output shape, flattening
99+ /// the SDK's `Option<Option<_>>` nullable fields and wrapping the
100+ /// SDK-required `default_catalog` as `Some`.
101+ fn from ( d : hotdata:: models:: DatabaseDetailResponse ) -> Self {
95102 Database {
96103 id : d. id ,
97104 name : d. name . flatten ( ) ,
@@ -110,9 +117,9 @@ impl Database {
110117 }
111118}
112119
113- impl DatabaseSummary {
114- /// Map the SDK's typed `DatabaseSummary` into the CLI's summary row.
115- fn from_sdk ( s : hotdata:: models:: DatabaseSummary ) -> Self {
120+ impl From < hotdata :: models :: DatabaseSummary > for DatabaseSummary {
121+ /// Map the SDK's typed summary into the CLI's list- row output shape .
122+ fn from ( s : hotdata:: models:: DatabaseSummary ) -> Self {
116123 DatabaseSummary {
117124 id : s. id ,
118125 name : s. name . flatten ( ) ,
@@ -127,18 +134,14 @@ impl DatabaseSummary {
127134/// of the id segment, so callers no longer hand-roll the path. The result is
128135/// mapped into the CLI's `Database`.
129136pub ( crate ) fn get_database ( api : & Api , id : & str ) -> Result < Database , ApiError > {
130- block ( api. client ( ) . databases ( ) . get ( id) ) . map ( Database :: from_detail )
137+ block ( api. client ( ) . databases ( ) . get ( id) ) . map ( Database :: from )
131138}
132139
133140/// List databases through the SDK's typed `databases().list` handle, mapped
134141/// into the CLI's summary rows.
135142fn list_database_summaries ( api : & Api ) -> Result < Vec < DatabaseSummary > , ApiError > {
136- block ( api. client ( ) . databases ( ) . list ( ) ) . map ( |r| {
137- r. databases
138- . into_iter ( )
139- . map ( DatabaseSummary :: from_sdk)
140- . collect ( )
141- } )
143+ block ( api. client ( ) . databases ( ) . list ( ) )
144+ . map ( |r| r. databases . into_iter ( ) . map ( DatabaseSummary :: from) . collect ( ) )
142145}
143146
144147fn fetch_database ( api : & Api , id : & str ) -> Database {
0 commit comments