samling_clorinde/queries/
style.rs

1// This file was generated with `clorinde`. Do not modify.
2
3#[derive(Debug)]
4pub struct SelectStylesParams<T1: crate::ArraySql<Item = i32>> {
5    pub organization_id: i32,
6    pub ids: Option<T1>,
7}
8#[derive(Debug)]
9pub struct SelectCollectionStylesNestedParams<
10    T1: crate::StringSql,
11    T2: crate::ArraySql<Item = T1>,
12    T3: crate::ArraySql<Item = i32>,
13    T4: crate::ArraySql<Item = i32>,
14> {
15    pub collection_id: i32,
16    pub organization_id: i32,
17    pub statuses: Option<T2>,
18    pub pricelist_ids_to_display: Option<T3>,
19    pub ids: Option<T4>,
20}
21#[derive(Debug)]
22pub struct SelectNestedStyleSummariesParams<
23    T1: crate::ArraySql<Item = i32>,
24    T2: crate::StringSql,
25    T3: crate::ArraySql<Item = T2>,
26    T4: crate::ArraySql<Item = i32>,
27    T5: crate::ArraySql<Item = i32>,
28> {
29    pub attributes: Option<T1>,
30    pub organization_id: i32,
31    pub statuses: Option<T3>,
32    pub ids: Option<T4>,
33    pub categories: Option<T5>,
34}
35#[derive(Debug)]
36pub struct GetStyleIdParams<T1: crate::StringSql, T2: crate::StringSql> {
37    pub organization_id: i32,
38    pub id: Option<i32>,
39    pub external_id: Option<T1>,
40    pub slug: Option<T2>,
41}
42#[derive(Debug)]
43pub struct GetStyleRefsParams<T1: crate::StringSql, T2: crate::StringSql> {
44    pub organization_id: i32,
45    pub id: Option<i32>,
46    pub external_id: Option<T1>,
47    pub slug: Option<T2>,
48}
49#[derive(Debug)]
50pub struct InsertStyleParams<
51    T1: crate::StringSql,
52    T2: crate::StringSql,
53    T3: crate::StringSql,
54    T4: crate::JsonSql,
55    T5: crate::JsonSql,
56    T6: crate::StringSql,
57    T7: crate::StringSql,
58> {
59    pub organization_id: i32,
60    pub slug: T1,
61    pub external_id: Option<T2>,
62    pub number: T3,
63    pub name: T4,
64    pub description: T5,
65    pub core: Option<bool>,
66    pub country_of_origin: Option<T6>,
67    pub tariff_no: Option<T7>,
68    pub net_weight: rust_decimal::Decimal,
69    pub gross_weight: rust_decimal::Decimal,
70    pub unit_volume: rust_decimal::Decimal,
71    pub created_by: i32,
72}
73#[derive(Debug)]
74pub struct UpdateStyleParams<
75    T1: crate::StringSql,
76    T2: crate::StringSql,
77    T3: crate::StringSql,
78    T4: crate::JsonSql,
79    T5: crate::JsonSql,
80    T6: crate::StringSql,
81    T7: crate::StringSql,
82> {
83    pub slug: Option<T1>,
84    pub external_id: Option<T2>,
85    pub number: Option<T3>,
86    pub name: Option<T4>,
87    pub description: Option<T5>,
88    pub core: Option<bool>,
89    pub country_of_origin: Option<T6>,
90    pub tariff_no: Option<T7>,
91    pub net_weight: Option<rust_decimal::Decimal>,
92    pub gross_weight: Option<rust_decimal::Decimal>,
93    pub unit_volume: Option<rust_decimal::Decimal>,
94    pub id: i32,
95}
96#[derive(Clone, Copy, Debug)]
97pub struct DeleteStyleParams {
98    pub organization_id: i32,
99    pub id: i32,
100}
101#[derive(Debug, Clone, PartialEq)]
102pub struct StyleRow {
103    pub id: i32,
104    pub organization_id: i32,
105    pub slug: String,
106    pub external_id: Option<String>,
107    pub number: String,
108    pub name: serde_json::Value,
109    pub created_by: Option<i32>,
110    pub created_at: chrono::DateTime<chrono::FixedOffset>,
111    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
112    pub description: serde_json::Value,
113    pub core: Option<bool>,
114    pub country_of_origin: Option<String>,
115    pub tariff_no: Option<String>,
116    pub unit_volume: rust_decimal::Decimal,
117    pub gross_weight: rust_decimal::Decimal,
118    pub net_weight: rust_decimal::Decimal,
119    pub categories: serde_json::Value,
120    pub attributes: serde_json::Value,
121}
122pub struct StyleRowBorrowed<'a> {
123    pub id: i32,
124    pub organization_id: i32,
125    pub slug: &'a str,
126    pub external_id: Option<&'a str>,
127    pub number: &'a str,
128    pub name: postgres_types::Json<&'a serde_json::value::RawValue>,
129    pub created_by: Option<i32>,
130    pub created_at: chrono::DateTime<chrono::FixedOffset>,
131    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
132    pub description: postgres_types::Json<&'a serde_json::value::RawValue>,
133    pub core: Option<bool>,
134    pub country_of_origin: Option<&'a str>,
135    pub tariff_no: Option<&'a str>,
136    pub unit_volume: rust_decimal::Decimal,
137    pub gross_weight: rust_decimal::Decimal,
138    pub net_weight: rust_decimal::Decimal,
139    pub categories: postgres_types::Json<&'a serde_json::value::RawValue>,
140    pub attributes: postgres_types::Json<&'a serde_json::value::RawValue>,
141}
142impl<'a> From<StyleRowBorrowed<'a>> for StyleRow {
143    fn from(
144        StyleRowBorrowed {
145            id,
146            organization_id,
147            slug,
148            external_id,
149            number,
150            name,
151            created_by,
152            created_at,
153            updated_at,
154            description,
155            core,
156            country_of_origin,
157            tariff_no,
158            unit_volume,
159            gross_weight,
160            net_weight,
161            categories,
162            attributes,
163        }: StyleRowBorrowed<'a>,
164    ) -> Self {
165        Self {
166            id,
167            organization_id,
168            slug: slug.into(),
169            external_id: external_id.map(|v| v.into()),
170            number: number.into(),
171            name: serde_json::from_str(name.0.get()).unwrap(),
172            created_by,
173            created_at,
174            updated_at,
175            description: serde_json::from_str(description.0.get()).unwrap(),
176            core,
177            country_of_origin: country_of_origin.map(|v| v.into()),
178            tariff_no: tariff_no.map(|v| v.into()),
179            unit_volume,
180            gross_weight,
181            net_weight,
182            categories: serde_json::from_str(categories.0.get()).unwrap(),
183            attributes: serde_json::from_str(attributes.0.get()).unwrap(),
184        }
185    }
186}
187#[derive(Debug, Clone, PartialEq)]
188pub struct NestedStyleRow {
189    pub id: i32,
190    pub organization_id: i32,
191    pub slug: String,
192    pub external_id: Option<String>,
193    pub number: String,
194    pub name: serde_json::Value,
195    pub created_by: Option<i32>,
196    pub created_at: chrono::DateTime<chrono::FixedOffset>,
197    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
198    pub description: serde_json::Value,
199    pub core: Option<bool>,
200    pub country_of_origin: Option<String>,
201    pub tariff_no: Option<String>,
202    pub unit_volume: rust_decimal::Decimal,
203    pub gross_weight: rust_decimal::Decimal,
204    pub net_weight: rust_decimal::Decimal,
205    pub is_new: Option<bool>,
206    pub colors: serde_json::Value,
207    pub prices: serde_json::Value,
208    pub attributes: serde_json::Value,
209    pub categories: serde_json::Value,
210}
211pub struct NestedStyleRowBorrowed<'a> {
212    pub id: i32,
213    pub organization_id: i32,
214    pub slug: &'a str,
215    pub external_id: Option<&'a str>,
216    pub number: &'a str,
217    pub name: postgres_types::Json<&'a serde_json::value::RawValue>,
218    pub created_by: Option<i32>,
219    pub created_at: chrono::DateTime<chrono::FixedOffset>,
220    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
221    pub description: postgres_types::Json<&'a serde_json::value::RawValue>,
222    pub core: Option<bool>,
223    pub country_of_origin: Option<&'a str>,
224    pub tariff_no: Option<&'a str>,
225    pub unit_volume: rust_decimal::Decimal,
226    pub gross_weight: rust_decimal::Decimal,
227    pub net_weight: rust_decimal::Decimal,
228    pub is_new: Option<bool>,
229    pub colors: postgres_types::Json<&'a serde_json::value::RawValue>,
230    pub prices: postgres_types::Json<&'a serde_json::value::RawValue>,
231    pub attributes: postgres_types::Json<&'a serde_json::value::RawValue>,
232    pub categories: postgres_types::Json<&'a serde_json::value::RawValue>,
233}
234impl<'a> From<NestedStyleRowBorrowed<'a>> for NestedStyleRow {
235    fn from(
236        NestedStyleRowBorrowed {
237            id,
238            organization_id,
239            slug,
240            external_id,
241            number,
242            name,
243            created_by,
244            created_at,
245            updated_at,
246            description,
247            core,
248            country_of_origin,
249            tariff_no,
250            unit_volume,
251            gross_weight,
252            net_weight,
253            is_new,
254            colors,
255            prices,
256            attributes,
257            categories,
258        }: NestedStyleRowBorrowed<'a>,
259    ) -> Self {
260        Self {
261            id,
262            organization_id,
263            slug: slug.into(),
264            external_id: external_id.map(|v| v.into()),
265            number: number.into(),
266            name: serde_json::from_str(name.0.get()).unwrap(),
267            created_by,
268            created_at,
269            updated_at,
270            description: serde_json::from_str(description.0.get()).unwrap(),
271            core,
272            country_of_origin: country_of_origin.map(|v| v.into()),
273            tariff_no: tariff_no.map(|v| v.into()),
274            unit_volume,
275            gross_weight,
276            net_weight,
277            is_new,
278            colors: serde_json::from_str(colors.0.get()).unwrap(),
279            prices: serde_json::from_str(prices.0.get()).unwrap(),
280            attributes: serde_json::from_str(attributes.0.get()).unwrap(),
281            categories: serde_json::from_str(categories.0.get()).unwrap(),
282        }
283    }
284}
285#[derive(Debug, Clone, PartialEq)]
286pub struct NestedStyleSummaryRow {
287    pub id: i32,
288    pub name: serde_json::Value,
289    pub number: String,
290    pub colors: serde_json::Value,
291}
292pub struct NestedStyleSummaryRowBorrowed<'a> {
293    pub id: i32,
294    pub name: postgres_types::Json<&'a serde_json::value::RawValue>,
295    pub number: &'a str,
296    pub colors: postgres_types::Json<&'a serde_json::value::RawValue>,
297}
298impl<'a> From<NestedStyleSummaryRowBorrowed<'a>> for NestedStyleSummaryRow {
299    fn from(
300        NestedStyleSummaryRowBorrowed {
301            id,
302            name,
303            number,
304            colors,
305        }: NestedStyleSummaryRowBorrowed<'a>,
306    ) -> Self {
307        Self {
308            id,
309            name: serde_json::from_str(name.0.get()).unwrap(),
310            number: number.into(),
311            colors: serde_json::from_str(colors.0.get()).unwrap(),
312        }
313    }
314}
315#[derive(Debug, Clone, PartialEq)]
316pub struct StyleRefs {
317    pub id: i32,
318    pub external_id: Option<String>,
319    pub slug: String,
320}
321pub struct StyleRefsBorrowed<'a> {
322    pub id: i32,
323    pub external_id: Option<&'a str>,
324    pub slug: &'a str,
325}
326impl<'a> From<StyleRefsBorrowed<'a>> for StyleRefs {
327    fn from(
328        StyleRefsBorrowed {
329            id,
330            external_id,
331            slug,
332        }: StyleRefsBorrowed<'a>,
333    ) -> Self {
334        Self {
335            id,
336            external_id: external_id.map(|v| v.into()),
337            slug: slug.into(),
338        }
339    }
340}
341use crate::client::async_::GenericClient;
342use futures::{self, StreamExt, TryStreamExt};
343pub struct StyleRowQuery<'a, C: GenericClient, T, const N: usize> {
344    client: &'a C,
345    params: [&'a (dyn postgres_types::ToSql + Sync); N],
346    stmt: &'a mut crate::client::async_::Stmt,
347    extractor: fn(&tokio_postgres::Row) -> StyleRowBorrowed,
348    mapper: fn(StyleRowBorrowed) -> T,
349}
350impl<'a, C, T: 'a, const N: usize> StyleRowQuery<'a, C, T, N>
351where
352    C: GenericClient,
353{
354    pub fn map<R>(self, mapper: fn(StyleRowBorrowed) -> R) -> StyleRowQuery<'a, C, R, N> {
355        StyleRowQuery {
356            client: self.client,
357            params: self.params,
358            stmt: self.stmt,
359            extractor: self.extractor,
360            mapper,
361        }
362    }
363    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
364        let stmt = self.stmt.prepare(self.client).await?;
365        let row = self.client.query_one(stmt, &self.params).await?;
366        Ok((self.mapper)((self.extractor)(&row)))
367    }
368    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
369        self.iter().await?.try_collect().await
370    }
371    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
372        let stmt = self.stmt.prepare(self.client).await?;
373        Ok(self
374            .client
375            .query_opt(stmt, &self.params)
376            .await?
377            .map(|row| (self.mapper)((self.extractor)(&row))))
378    }
379    pub async fn iter(
380        self,
381    ) -> Result<
382        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
383        tokio_postgres::Error,
384    > {
385        let stmt = self.stmt.prepare(self.client).await?;
386        let it = self
387            .client
388            .query_raw(stmt, crate::slice_iter(&self.params))
389            .await?
390            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
391            .into_stream();
392        Ok(it)
393    }
394}
395pub struct NestedStyleRowQuery<'a, C: GenericClient, T, const N: usize> {
396    client: &'a C,
397    params: [&'a (dyn postgres_types::ToSql + Sync); N],
398    stmt: &'a mut crate::client::async_::Stmt,
399    extractor: fn(&tokio_postgres::Row) -> NestedStyleRowBorrowed,
400    mapper: fn(NestedStyleRowBorrowed) -> T,
401}
402impl<'a, C, T: 'a, const N: usize> NestedStyleRowQuery<'a, C, T, N>
403where
404    C: GenericClient,
405{
406    pub fn map<R>(
407        self,
408        mapper: fn(NestedStyleRowBorrowed) -> R,
409    ) -> NestedStyleRowQuery<'a, C, R, N> {
410        NestedStyleRowQuery {
411            client: self.client,
412            params: self.params,
413            stmt: self.stmt,
414            extractor: self.extractor,
415            mapper,
416        }
417    }
418    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
419        let stmt = self.stmt.prepare(self.client).await?;
420        let row = self.client.query_one(stmt, &self.params).await?;
421        Ok((self.mapper)((self.extractor)(&row)))
422    }
423    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
424        self.iter().await?.try_collect().await
425    }
426    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
427        let stmt = self.stmt.prepare(self.client).await?;
428        Ok(self
429            .client
430            .query_opt(stmt, &self.params)
431            .await?
432            .map(|row| (self.mapper)((self.extractor)(&row))))
433    }
434    pub async fn iter(
435        self,
436    ) -> Result<
437        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
438        tokio_postgres::Error,
439    > {
440        let stmt = self.stmt.prepare(self.client).await?;
441        let it = self
442            .client
443            .query_raw(stmt, crate::slice_iter(&self.params))
444            .await?
445            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
446            .into_stream();
447        Ok(it)
448    }
449}
450pub struct NestedStyleSummaryRowQuery<'a, C: GenericClient, T, const N: usize> {
451    client: &'a C,
452    params: [&'a (dyn postgres_types::ToSql + Sync); N],
453    stmt: &'a mut crate::client::async_::Stmt,
454    extractor: fn(&tokio_postgres::Row) -> NestedStyleSummaryRowBorrowed,
455    mapper: fn(NestedStyleSummaryRowBorrowed) -> T,
456}
457impl<'a, C, T: 'a, const N: usize> NestedStyleSummaryRowQuery<'a, C, T, N>
458where
459    C: GenericClient,
460{
461    pub fn map<R>(
462        self,
463        mapper: fn(NestedStyleSummaryRowBorrowed) -> R,
464    ) -> NestedStyleSummaryRowQuery<'a, C, R, N> {
465        NestedStyleSummaryRowQuery {
466            client: self.client,
467            params: self.params,
468            stmt: self.stmt,
469            extractor: self.extractor,
470            mapper,
471        }
472    }
473    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
474        let stmt = self.stmt.prepare(self.client).await?;
475        let row = self.client.query_one(stmt, &self.params).await?;
476        Ok((self.mapper)((self.extractor)(&row)))
477    }
478    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
479        self.iter().await?.try_collect().await
480    }
481    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
482        let stmt = self.stmt.prepare(self.client).await?;
483        Ok(self
484            .client
485            .query_opt(stmt, &self.params)
486            .await?
487            .map(|row| (self.mapper)((self.extractor)(&row))))
488    }
489    pub async fn iter(
490        self,
491    ) -> Result<
492        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
493        tokio_postgres::Error,
494    > {
495        let stmt = self.stmt.prepare(self.client).await?;
496        let it = self
497            .client
498            .query_raw(stmt, crate::slice_iter(&self.params))
499            .await?
500            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
501            .into_stream();
502        Ok(it)
503    }
504}
505pub struct I32Query<'a, C: GenericClient, T, const N: usize> {
506    client: &'a C,
507    params: [&'a (dyn postgres_types::ToSql + Sync); N],
508    stmt: &'a mut crate::client::async_::Stmt,
509    extractor: fn(&tokio_postgres::Row) -> i32,
510    mapper: fn(i32) -> T,
511}
512impl<'a, C, T: 'a, const N: usize> I32Query<'a, C, T, N>
513where
514    C: GenericClient,
515{
516    pub fn map<R>(self, mapper: fn(i32) -> R) -> I32Query<'a, C, R, N> {
517        I32Query {
518            client: self.client,
519            params: self.params,
520            stmt: self.stmt,
521            extractor: self.extractor,
522            mapper,
523        }
524    }
525    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
526        let stmt = self.stmt.prepare(self.client).await?;
527        let row = self.client.query_one(stmt, &self.params).await?;
528        Ok((self.mapper)((self.extractor)(&row)))
529    }
530    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
531        self.iter().await?.try_collect().await
532    }
533    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
534        let stmt = self.stmt.prepare(self.client).await?;
535        Ok(self
536            .client
537            .query_opt(stmt, &self.params)
538            .await?
539            .map(|row| (self.mapper)((self.extractor)(&row))))
540    }
541    pub async fn iter(
542        self,
543    ) -> Result<
544        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
545        tokio_postgres::Error,
546    > {
547        let stmt = self.stmt.prepare(self.client).await?;
548        let it = self
549            .client
550            .query_raw(stmt, crate::slice_iter(&self.params))
551            .await?
552            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
553            .into_stream();
554        Ok(it)
555    }
556}
557pub struct StyleRefsQuery<'a, C: GenericClient, T, const N: usize> {
558    client: &'a C,
559    params: [&'a (dyn postgres_types::ToSql + Sync); N],
560    stmt: &'a mut crate::client::async_::Stmt,
561    extractor: fn(&tokio_postgres::Row) -> StyleRefsBorrowed,
562    mapper: fn(StyleRefsBorrowed) -> T,
563}
564impl<'a, C, T: 'a, const N: usize> StyleRefsQuery<'a, C, T, N>
565where
566    C: GenericClient,
567{
568    pub fn map<R>(self, mapper: fn(StyleRefsBorrowed) -> R) -> StyleRefsQuery<'a, C, R, N> {
569        StyleRefsQuery {
570            client: self.client,
571            params: self.params,
572            stmt: self.stmt,
573            extractor: self.extractor,
574            mapper,
575        }
576    }
577    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
578        let stmt = self.stmt.prepare(self.client).await?;
579        let row = self.client.query_one(stmt, &self.params).await?;
580        Ok((self.mapper)((self.extractor)(&row)))
581    }
582    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
583        self.iter().await?.try_collect().await
584    }
585    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
586        let stmt = self.stmt.prepare(self.client).await?;
587        Ok(self
588            .client
589            .query_opt(stmt, &self.params)
590            .await?
591            .map(|row| (self.mapper)((self.extractor)(&row))))
592    }
593    pub async fn iter(
594        self,
595    ) -> Result<
596        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
597        tokio_postgres::Error,
598    > {
599        let stmt = self.stmt.prepare(self.client).await?;
600        let it = self
601            .client
602            .query_raw(stmt, crate::slice_iter(&self.params))
603            .await?
604            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
605            .into_stream();
606        Ok(it)
607    }
608}
609pub fn select_styles() -> SelectStylesStmt {
610    SelectStylesStmt(crate::client::async_::Stmt::new(
611        "SELECT
612    style.*,
613    coalesce(joined_categories.json_data, '[]') AS \"categories\",
614    coalesce(joined_attributes.json_data, '[]') AS \"attributes\"
615FROM
616    style
617LEFT JOIN (
618    SELECT
619        style_attribute.style_id,
620        json_agg(
621            json_build_object(
622                'id',
623                \"attribute\".id,
624                'title',
625                \"attribute\".title,
626                'description',
627                \"attribute\".description,
628                'slug',
629                \"attribute\".slug,
630                'external_id',
631                \"attribute\".external_id,
632                'type',
633                json_build_object(
634                    'id',
635                    attributetype.id,
636                    'name',
637                    attributetype.name,
638                    'slug',
639                    attributetype.slug,
640                    'external_id',
641                    attributetype.external_id
642                )
643            )
644            ORDER BY
645                attributetype.name,
646                \"attribute\".title
647        ) FILTER (
648            WHERE
649            \"attribute\".id IS NOT NULL
650        ) AS json_data
651    FROM
652        attribute
653    INNER JOIN attributetype ON attributetype.id = \"attribute\".type_id
654    INNER JOIN style_attribute ON \"attribute\".id = style_attribute.attribute_id
655    WHERE
656        \"attribute\".organization_id = $1
657    GROUP BY
658        style_attribute.style_id
659    ) AS joined_attributes ON joined_attributes.style_id = style.id
660LEFT JOIN (
661    SELECT
662        style_category.style_id,
663        json_agg(category.*) FILTER (
664            WHERE
665            category.id IS NOT NULL
666        ) AS \"json_data\"
667    FROM
668        category
669    INNER JOIN style_category ON category.id = style_category.category_id
670    WHERE
671        category.organization_id = $1
672    GROUP BY
673        style_category.style_id
674    ) AS joined_categories ON joined_categories.style_id = style.id
675WHERE
676    style.organization_id = $1
677    AND $2::int[] IS NULL OR style.id = any($2)
678ORDER BY
679    style.number",
680    ))
681}
682pub struct SelectStylesStmt(crate::client::async_::Stmt);
683impl SelectStylesStmt {
684    pub fn bind<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>(
685        &'a mut self,
686        client: &'a C,
687        organization_id: &'a i32,
688        ids: &'a Option<T1>,
689    ) -> StyleRowQuery<'a, C, StyleRow, 2> {
690        StyleRowQuery {
691            client,
692            params: [organization_id, ids],
693            stmt: &mut self.0,
694            extractor: |row| StyleRowBorrowed {
695                id: row.get(0),
696                organization_id: row.get(1),
697                slug: row.get(2),
698                external_id: row.get(3),
699                number: row.get(4),
700                name: row.get(5),
701                created_by: row.get(6),
702                created_at: row.get(7),
703                updated_at: row.get(8),
704                description: row.get(9),
705                core: row.get(10),
706                country_of_origin: row.get(11),
707                tariff_no: row.get(12),
708                unit_volume: row.get(13),
709                gross_weight: row.get(14),
710                net_weight: row.get(15),
711                categories: row.get(16),
712                attributes: row.get(17),
713            },
714            mapper: |it| <StyleRow>::from(it),
715        }
716    }
717}
718impl<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>
719    crate::client::async_::Params<'a, SelectStylesParams<T1>, StyleRowQuery<'a, C, StyleRow, 2>, C>
720    for SelectStylesStmt
721{
722    fn params(
723        &'a mut self,
724        client: &'a C,
725        params: &'a SelectStylesParams<T1>,
726    ) -> StyleRowQuery<'a, C, StyleRow, 2> {
727        self.bind(client, &params.organization_id, &params.ids)
728    }
729}
730pub fn select_collection_styles_nested() -> SelectCollectionStylesNestedStmt {
731    SelectCollectionStylesNestedStmt(crate::client::async_::Stmt::new(
732        "WITH new_styles AS (
733    SELECT
734        new_collection_style.style_id,
735        new_collection_style.is_new
736    FROM
737        new_collection_style
738    WHERE
739        new_collection_style.collection_id = $1
740),
741
742new_colors AS (
743    SELECT
744        new_collection_color.color_id,
745        new_collection_color.is_new
746    FROM
747        new_collection_color
748    WHERE
749        new_collection_color.collection_id = $1
750)
751
752SELECT
753    style.*,
754    new_styles.is_new,
755    coalesce(joined_colors.json_data, '[]') AS \"colors\",
756    coalesce(joined_prices.json_data, '[]') AS \"prices\",
757    coalesce(joined_attributes.json_data, '[]') AS \"attributes\",
758    coalesce(joined_categories.json_data, '[]') AS \"categories\"
759FROM
760    style
761LEFT JOIN new_styles ON new_styles.style_id = style.id
762INNER JOIN (
763        SELECT
764            color.style_id,
765            json_agg(
766                json_build_object(
767                    'id',
768                    color.id,
769                    'number',
770                    color.number,
771                    'name',
772                    color.name,
773                    'slug',
774                    color.slug,
775                    'external_id',
776                    color.external_id,
777                    'sizes', coalesce(joined_sizes.json_data, '[]'),
778                    'images', coalesce(joined_images.json_data, '[]'),
779                    'is_new',
780                    new_colors.is_new
781                )
782                ORDER BY
783                    color.number
784            ) FILTER (
785                WHERE
786                color.id IS NOT NULL
787            ) AS json_data
788        FROM
789            color
790        LEFT JOIN new_colors ON new_colors.color_id = color.id
791        INNER JOIN (
792            SELECT
793                size.color_id,
794                json_agg(
795                    json_build_object(
796                        'id',
797                        size.id,
798                        'number',
799                        size.number,
800                        'position',
801                        size.position,
802                        'name',
803                        size.name,
804                        'service_item',
805                        size.service_item,
806                        'delivery_period',
807                        size.delivery_period,
808                        'ean_code',
809                        size.ean_code,
810                        'status',
811                        size.status,
812                        'slug',
813                        size.slug,
814                        'external_id',
815                        size.external_id
816                    )
817                    ORDER BY
818                        size.number
819                ) FILTER (
820                    WHERE
821                    size.id IS NOT NULL
822                ) AS json_data
823            FROM
824                size
825            INNER JOIN color ON size.color_id = color.id
826            INNER JOIN style ON color.style_id = style.id
827            INNER JOIN size_collection ON size_collection.size_id = size.id
828            WHERE
829                size.organization_id = $2
830                AND size_collection.collection_id = $1
831                AND (
832                    $3::text[] IS NULL OR size.status = any($3)
833                )
834            GROUP BY
835                size.color_id
836            ) AS joined_sizes ON joined_sizes.color_id = color.id
837        LEFT JOIN (
838            SELECT
839                image.color_id,
840                json_agg(
841                    json_build_object(
842                        'id',
843                        image.id,
844                        'url',
845                        image.url,
846                        'external_id',
847                        image.external_id
848                    )
849                    ORDER BY
850                        image.position ASC,
851                        image.uploaded_at DESC
852                ) AS json_data
853            FROM
854                image
855            WHERE
856                image.organization_id = $2
857            GROUP BY
858                image.color_id
859            ) AS joined_images ON joined_images.color_id = color.id
860        WHERE
861            color.organization_id = $2
862        GROUP BY
863            color.style_id
864    ) AS joined_colors ON joined_colors.style_id = style.id
865LEFT JOIN (
866        SELECT
867            price.style_id,
868            json_agg(
869                json_build_object(
870                    'id',
871                    price.id,
872                    'type',
873                    price.type,
874                    'uom',
875                    price.uom,
876                    'currency',
877                    price.currency,
878                    'amount',
879                    price.amount,
880                    'start',
881                    price.start,
882                    'end',
883                    price.end,
884                    'list',
885                    json_build_object(
886                        'id',
887                        pricelist.id,
888                        'slug',
889                        pricelist.slug,
890                        'external_id',
891                        pricelist.external_id,
892                        'name',
893                        pricelist.name
894                    )
895                )
896                ORDER BY
897                    price.type,
898                    pricelist.name,
899                    price.\"start\"
900            ) FILTER (
901                WHERE
902                price.id IS NOT NULL
903            ) AS json_data
904        FROM
905            price
906        INNER JOIN pricelist ON pricelist.id = price.list_id
907        INNER JOIN collection_pricelist ON
908            collection_pricelist.pricelist_id = pricelist.id
909        WHERE
910            price.organization_id = $2
911            AND (
912                $4::int[] IS NULL
913                OR pricelist.id = any($4)
914            )
915            AND collection_pricelist.collection_id = $1
916            AND (
917                collection_pricelist.price_date
918                BETWEEN price.\"start\" AND price.\"end\"
919            )
920        GROUP BY
921            price.style_id
922    ) AS joined_prices ON joined_prices.style_id = style.id
923LEFT JOIN (
924        SELECT
925            style_attribute.style_id,
926            json_agg(
927                json_build_object(
928                    'id',
929                    \"attribute\".id,
930                    'title',
931                    \"attribute\".title,
932                    'description',
933                    \"attribute\".description,
934                    'slug',
935                    \"attribute\".slug,
936                    'external_id',
937                    \"attribute\".external_id,
938                    'type',
939                    json_build_object(
940                        'id',
941                        attributetype.id,
942                        'name',
943                        attributetype.name,
944                        'slug',
945                        attributetype.slug,
946                        'external_id',
947                        attributetype.external_id
948                    )
949                )
950                ORDER BY
951                    attributetype.name,
952                    \"attribute\".title
953            ) FILTER (
954                WHERE
955                \"attribute\".id IS NOT NULL
956            ) AS json_data
957        FROM
958            attribute
959        INNER JOIN attributetype ON attributetype.id = \"attribute\".type_id
960        INNER JOIN style_attribute ON \"attribute\".id = style_attribute.attribute_id
961        WHERE
962            \"attribute\".organization_id = $2
963        GROUP BY
964            style_attribute.style_id
965    ) AS joined_attributes ON joined_attributes.style_id = style.id
966LEFT JOIN (
967        SELECT
968            style_category.style_id,
969            json_agg(
970                json_build_object(
971                    'id',
972                    category.id,
973                    'slug',
974                    category.slug,
975                    'name',
976                    category.name,
977                    'external_id',
978                    category.external_id
979                )
980            ) FILTER (
981                WHERE
982                category.id IS NOT NULL
983            ) AS \"json_data\"
984        FROM
985            category
986        INNER JOIN style_category ON category.id = style_category.category_id
987        WHERE
988            category.organization_id = $2
989        GROUP BY
990            style_category.style_id
991    ) AS joined_categories ON joined_categories.style_id = style.id
992WHERE
993    ($5::int[] IS NULL OR style.id = any($5))
994ORDER BY
995    style.number",
996    ))
997}
998pub struct SelectCollectionStylesNestedStmt(crate::client::async_::Stmt);
999impl SelectCollectionStylesNestedStmt {
1000    pub fn bind<
1001        'a,
1002        C: GenericClient,
1003        T1: crate::StringSql,
1004        T2: crate::ArraySql<Item = T1>,
1005        T3: crate::ArraySql<Item = i32>,
1006        T4: crate::ArraySql<Item = i32>,
1007    >(
1008        &'a mut self,
1009        client: &'a C,
1010        collection_id: &'a i32,
1011        organization_id: &'a i32,
1012        statuses: &'a Option<T2>,
1013        pricelist_ids_to_display: &'a Option<T3>,
1014        ids: &'a Option<T4>,
1015    ) -> NestedStyleRowQuery<'a, C, NestedStyleRow, 5> {
1016        NestedStyleRowQuery {
1017            client,
1018            params: [
1019                collection_id,
1020                organization_id,
1021                statuses,
1022                pricelist_ids_to_display,
1023                ids,
1024            ],
1025            stmt: &mut self.0,
1026            extractor: |row| NestedStyleRowBorrowed {
1027                id: row.get(0),
1028                organization_id: row.get(1),
1029                slug: row.get(2),
1030                external_id: row.get(3),
1031                number: row.get(4),
1032                name: row.get(5),
1033                created_by: row.get(6),
1034                created_at: row.get(7),
1035                updated_at: row.get(8),
1036                description: row.get(9),
1037                core: row.get(10),
1038                country_of_origin: row.get(11),
1039                tariff_no: row.get(12),
1040                unit_volume: row.get(13),
1041                gross_weight: row.get(14),
1042                net_weight: row.get(15),
1043                is_new: row.get(16),
1044                colors: row.get(17),
1045                prices: row.get(18),
1046                attributes: row.get(19),
1047                categories: row.get(20),
1048            },
1049            mapper: |it| <NestedStyleRow>::from(it),
1050        }
1051    }
1052}
1053impl<
1054        'a,
1055        C: GenericClient,
1056        T1: crate::StringSql,
1057        T2: crate::ArraySql<Item = T1>,
1058        T3: crate::ArraySql<Item = i32>,
1059        T4: crate::ArraySql<Item = i32>,
1060    >
1061    crate::client::async_::Params<
1062        'a,
1063        SelectCollectionStylesNestedParams<T1, T2, T3, T4>,
1064        NestedStyleRowQuery<'a, C, NestedStyleRow, 5>,
1065        C,
1066    > for SelectCollectionStylesNestedStmt
1067{
1068    fn params(
1069        &'a mut self,
1070        client: &'a C,
1071        params: &'a SelectCollectionStylesNestedParams<T1, T2, T3, T4>,
1072    ) -> NestedStyleRowQuery<'a, C, NestedStyleRow, 5> {
1073        self.bind(
1074            client,
1075            &params.collection_id,
1076            &params.organization_id,
1077            &params.statuses,
1078            &params.pricelist_ids_to_display,
1079            &params.ids,
1080        )
1081    }
1082}
1083pub fn select_nested_style_summaries() -> SelectNestedStyleSummariesStmt {
1084    SelectNestedStyleSummariesStmt(crate::client::async_::Stmt::new(
1085        "WITH attribute_matches AS (
1086    SELECT styles_matching_attributes($1)
1087)
1088
1089SELECT
1090    style.id,
1091    style.name,
1092    style.number,
1093    coalesce(joined_colors.json_data, '[]') AS \"colors\"
1094FROM
1095    style
1096INNER JOIN (
1097        SELECT
1098            color.style_id,
1099            json_agg(
1100                json_build_object(
1101                    'id',
1102                    color.id,
1103                    'number',
1104                    color.number,
1105                    'name',
1106                    color.name,
1107                    'sizes', coalesce(joined_sizes.json_data, '[]'),
1108                    'primary_image', primary_image.json_data
1109                )
1110                ORDER BY
1111                    color.number
1112            ) FILTER (
1113                WHERE
1114                color.id IS NOT NULL
1115            ) AS json_data
1116        FROM
1117            color
1118        INNER JOIN (
1119            SELECT
1120                size.color_id,
1121                json_agg(
1122                    json_build_object(
1123                        'id',
1124                        size.id,
1125                        'number',
1126                        size.number,
1127                        'name',
1128                        size.name
1129                    )
1130                    ORDER BY
1131                        size.number
1132                ) FILTER (
1133                    WHERE
1134                    size.id IS NOT NULL
1135                ) AS json_data
1136            FROM
1137                size
1138            INNER JOIN color ON size.color_id = color.id
1139            WHERE
1140                size.organization_id = $2
1141                AND ($3::text[] IS NULL OR size.status = any($3))
1142            GROUP BY
1143                size.color_id
1144            ) AS joined_sizes ON joined_sizes.color_id = color.id
1145        LEFT JOIN (
1146            -- We utilize distinct here because there might be multiple rows with
1147            -- `position = 1` for a given `color_id`.
1148            SELECT DISTINCT ON (image.color_id)
1149                image.color_id,
1150                json_build_object(
1151                    'id',
1152                    image.id,
1153                    'url',
1154                    image.url,
1155                    'external_id',
1156                    image.external_id
1157                ) AS json_data
1158            FROM
1159                image
1160            WHERE
1161                image.organization_id = $2
1162                AND image.position = 1
1163            ) AS primary_image ON primary_image.color_id = color.id
1164        WHERE
1165            color.organization_id = $2
1166        GROUP BY
1167            color.style_id
1168    ) AS joined_colors ON joined_colors.style_id = style.id
1169LEFT JOIN (
1170    SELECT
1171        style_category.style_id,
1172        array_agg(style_category.category_id) AS category_ids
1173    FROM style_category
1174    GROUP BY style_category.style_id
1175) AS style_categories ON style_categories.style_id = style.id
1176WHERE
1177    style.organization_id = $2
1178    AND ($4::int[] IS NULL OR style.id = any($4))
1179    AND ($5::int[] IS NULL OR style_categories.category_ids && $5)
1180    AND ($1::int[] IS NULL OR style.id IN (SELECT * FROM attribute_matches))
1181ORDER BY
1182    style.number",
1183    ))
1184}
1185pub struct SelectNestedStyleSummariesStmt(crate::client::async_::Stmt);
1186impl SelectNestedStyleSummariesStmt {
1187    pub fn bind<
1188        'a,
1189        C: GenericClient,
1190        T1: crate::ArraySql<Item = i32>,
1191        T2: crate::StringSql,
1192        T3: crate::ArraySql<Item = T2>,
1193        T4: crate::ArraySql<Item = i32>,
1194        T5: crate::ArraySql<Item = i32>,
1195    >(
1196        &'a mut self,
1197        client: &'a C,
1198        attributes: &'a Option<T1>,
1199        organization_id: &'a i32,
1200        statuses: &'a Option<T3>,
1201        ids: &'a Option<T4>,
1202        categories: &'a Option<T5>,
1203    ) -> NestedStyleSummaryRowQuery<'a, C, NestedStyleSummaryRow, 5> {
1204        NestedStyleSummaryRowQuery {
1205            client,
1206            params: [attributes, organization_id, statuses, ids, categories],
1207            stmt: &mut self.0,
1208            extractor: |row| NestedStyleSummaryRowBorrowed {
1209                id: row.get(0),
1210                name: row.get(1),
1211                number: row.get(2),
1212                colors: row.get(3),
1213            },
1214            mapper: |it| <NestedStyleSummaryRow>::from(it),
1215        }
1216    }
1217}
1218impl<
1219        'a,
1220        C: GenericClient,
1221        T1: crate::ArraySql<Item = i32>,
1222        T2: crate::StringSql,
1223        T3: crate::ArraySql<Item = T2>,
1224        T4: crate::ArraySql<Item = i32>,
1225        T5: crate::ArraySql<Item = i32>,
1226    >
1227    crate::client::async_::Params<
1228        'a,
1229        SelectNestedStyleSummariesParams<T1, T2, T3, T4, T5>,
1230        NestedStyleSummaryRowQuery<'a, C, NestedStyleSummaryRow, 5>,
1231        C,
1232    > for SelectNestedStyleSummariesStmt
1233{
1234    fn params(
1235        &'a mut self,
1236        client: &'a C,
1237        params: &'a SelectNestedStyleSummariesParams<T1, T2, T3, T4, T5>,
1238    ) -> NestedStyleSummaryRowQuery<'a, C, NestedStyleSummaryRow, 5> {
1239        self.bind(
1240            client,
1241            &params.attributes,
1242            &params.organization_id,
1243            &params.statuses,
1244            &params.ids,
1245            &params.categories,
1246        )
1247    }
1248}
1249pub fn get_style_id() -> GetStyleIdStmt {
1250    GetStyleIdStmt(crate::client::async_::Stmt::new(
1251        "SELECT style.id
1252FROM
1253    style
1254WHERE
1255    style.organization_id = $1
1256    AND (
1257        (style.id = coalesce($2, -1))
1258        OR (
1259            style.external_id = coalesce($3, '___NON_EXISTING___')
1260            OR (style.slug = coalesce($4, '___NON_EXISTING___'))
1261        )
1262    )",
1263    ))
1264}
1265pub struct GetStyleIdStmt(crate::client::async_::Stmt);
1266impl GetStyleIdStmt {
1267    pub fn bind<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>(
1268        &'a mut self,
1269        client: &'a C,
1270        organization_id: &'a i32,
1271        id: &'a Option<i32>,
1272        external_id: &'a Option<T1>,
1273        slug: &'a Option<T2>,
1274    ) -> I32Query<'a, C, i32, 4> {
1275        I32Query {
1276            client,
1277            params: [organization_id, id, external_id, slug],
1278            stmt: &mut self.0,
1279            extractor: |row| row.get(0),
1280            mapper: |it| it,
1281        }
1282    }
1283}
1284impl<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>
1285    crate::client::async_::Params<'a, GetStyleIdParams<T1, T2>, I32Query<'a, C, i32, 4>, C>
1286    for GetStyleIdStmt
1287{
1288    fn params(
1289        &'a mut self,
1290        client: &'a C,
1291        params: &'a GetStyleIdParams<T1, T2>,
1292    ) -> I32Query<'a, C, i32, 4> {
1293        self.bind(
1294            client,
1295            &params.organization_id,
1296            &params.id,
1297            &params.external_id,
1298            &params.slug,
1299        )
1300    }
1301}
1302pub fn get_style_refs() -> GetStyleRefsStmt {
1303    GetStyleRefsStmt(crate::client::async_::Stmt::new(
1304        "SELECT
1305    style.id,
1306    style.external_id,
1307    style.slug
1308FROM
1309    style
1310WHERE
1311    style.organization_id = $1
1312    AND (
1313        (style.id = coalesce($2, -1))
1314        OR (
1315            style.external_id = coalesce($3, '___NON_EXISTING___')
1316            OR (style.slug = coalesce($4, '___NON_EXISTING___'))
1317        )
1318    )",
1319    ))
1320}
1321pub struct GetStyleRefsStmt(crate::client::async_::Stmt);
1322impl GetStyleRefsStmt {
1323    pub fn bind<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>(
1324        &'a mut self,
1325        client: &'a C,
1326        organization_id: &'a i32,
1327        id: &'a Option<i32>,
1328        external_id: &'a Option<T1>,
1329        slug: &'a Option<T2>,
1330    ) -> StyleRefsQuery<'a, C, StyleRefs, 4> {
1331        StyleRefsQuery {
1332            client,
1333            params: [organization_id, id, external_id, slug],
1334            stmt: &mut self.0,
1335            extractor: |row| StyleRefsBorrowed {
1336                id: row.get(0),
1337                external_id: row.get(1),
1338                slug: row.get(2),
1339            },
1340            mapper: |it| <StyleRefs>::from(it),
1341        }
1342    }
1343}
1344impl<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>
1345    crate::client::async_::Params<
1346        'a,
1347        GetStyleRefsParams<T1, T2>,
1348        StyleRefsQuery<'a, C, StyleRefs, 4>,
1349        C,
1350    > for GetStyleRefsStmt
1351{
1352    fn params(
1353        &'a mut self,
1354        client: &'a C,
1355        params: &'a GetStyleRefsParams<T1, T2>,
1356    ) -> StyleRefsQuery<'a, C, StyleRefs, 4> {
1357        self.bind(
1358            client,
1359            &params.organization_id,
1360            &params.id,
1361            &params.external_id,
1362            &params.slug,
1363        )
1364    }
1365}
1366pub fn insert_style() -> InsertStyleStmt {
1367    InsertStyleStmt(crate::client::async_::Stmt::new(
1368        "INSERT INTO
1369style (
1370    organization_id,
1371    slug,
1372    external_id,
1373    number,
1374    name,
1375    description,
1376    core,
1377    country_of_origin,
1378    tariff_no,
1379    net_weight,
1380    gross_weight,
1381    unit_volume,
1382    created_by
1383)
1384VALUES
1385(
1386    $1,
1387    $2,
1388    $3,
1389    $4,
1390    $5,
1391    $6,
1392    $7,
1393    $8,
1394    $9,
1395    $10,
1396    $11,
1397    $12,
1398    $13
1399)
1400RETURNING
1401id",
1402    ))
1403}
1404pub struct InsertStyleStmt(crate::client::async_::Stmt);
1405impl InsertStyleStmt {
1406    pub fn bind<
1407        'a,
1408        C: GenericClient,
1409        T1: crate::StringSql,
1410        T2: crate::StringSql,
1411        T3: crate::StringSql,
1412        T4: crate::JsonSql,
1413        T5: crate::JsonSql,
1414        T6: crate::StringSql,
1415        T7: crate::StringSql,
1416    >(
1417        &'a mut self,
1418        client: &'a C,
1419        organization_id: &'a i32,
1420        slug: &'a T1,
1421        external_id: &'a Option<T2>,
1422        number: &'a T3,
1423        name: &'a T4,
1424        description: &'a T5,
1425        core: &'a Option<bool>,
1426        country_of_origin: &'a Option<T6>,
1427        tariff_no: &'a Option<T7>,
1428        net_weight: &'a rust_decimal::Decimal,
1429        gross_weight: &'a rust_decimal::Decimal,
1430        unit_volume: &'a rust_decimal::Decimal,
1431        created_by: &'a i32,
1432    ) -> I32Query<'a, C, i32, 13> {
1433        I32Query {
1434            client,
1435            params: [
1436                organization_id,
1437                slug,
1438                external_id,
1439                number,
1440                name,
1441                description,
1442                core,
1443                country_of_origin,
1444                tariff_no,
1445                net_weight,
1446                gross_weight,
1447                unit_volume,
1448                created_by,
1449            ],
1450            stmt: &mut self.0,
1451            extractor: |row| row.get(0),
1452            mapper: |it| it,
1453        }
1454    }
1455}
1456impl<
1457        'a,
1458        C: GenericClient,
1459        T1: crate::StringSql,
1460        T2: crate::StringSql,
1461        T3: crate::StringSql,
1462        T4: crate::JsonSql,
1463        T5: crate::JsonSql,
1464        T6: crate::StringSql,
1465        T7: crate::StringSql,
1466    >
1467    crate::client::async_::Params<
1468        'a,
1469        InsertStyleParams<T1, T2, T3, T4, T5, T6, T7>,
1470        I32Query<'a, C, i32, 13>,
1471        C,
1472    > for InsertStyleStmt
1473{
1474    fn params(
1475        &'a mut self,
1476        client: &'a C,
1477        params: &'a InsertStyleParams<T1, T2, T3, T4, T5, T6, T7>,
1478    ) -> I32Query<'a, C, i32, 13> {
1479        self.bind(
1480            client,
1481            &params.organization_id,
1482            &params.slug,
1483            &params.external_id,
1484            &params.number,
1485            &params.name,
1486            &params.description,
1487            &params.core,
1488            &params.country_of_origin,
1489            &params.tariff_no,
1490            &params.net_weight,
1491            &params.gross_weight,
1492            &params.unit_volume,
1493            &params.created_by,
1494        )
1495    }
1496}
1497pub fn update_style() -> UpdateStyleStmt {
1498    UpdateStyleStmt(crate::client::async_::Stmt::new(
1499        "UPDATE
1500style
1501SET
1502    slug = coalesce($1, slug),
1503    external_id = coalesce($2, external_id),
1504    number = coalesce($3, number),
1505    name = coalesce($4, name),
1506    description = coalesce($5, description),
1507    core = coalesce($6, core),
1508    country_of_origin = coalesce($7, country_of_origin),
1509    tariff_no = coalesce($8, tariff_no),
1510    net_weight = coalesce($9, net_weight),
1511    gross_weight = coalesce($10, gross_weight),
1512    unit_volume = coalesce($11, unit_volume)
1513WHERE
1514    id = $12
1515RETURNING
1516id",
1517    ))
1518}
1519pub struct UpdateStyleStmt(crate::client::async_::Stmt);
1520impl UpdateStyleStmt {
1521    pub fn bind<
1522        'a,
1523        C: GenericClient,
1524        T1: crate::StringSql,
1525        T2: crate::StringSql,
1526        T3: crate::StringSql,
1527        T4: crate::JsonSql,
1528        T5: crate::JsonSql,
1529        T6: crate::StringSql,
1530        T7: crate::StringSql,
1531    >(
1532        &'a mut self,
1533        client: &'a C,
1534        slug: &'a Option<T1>,
1535        external_id: &'a Option<T2>,
1536        number: &'a Option<T3>,
1537        name: &'a Option<T4>,
1538        description: &'a Option<T5>,
1539        core: &'a Option<bool>,
1540        country_of_origin: &'a Option<T6>,
1541        tariff_no: &'a Option<T7>,
1542        net_weight: &'a Option<rust_decimal::Decimal>,
1543        gross_weight: &'a Option<rust_decimal::Decimal>,
1544        unit_volume: &'a Option<rust_decimal::Decimal>,
1545        id: &'a i32,
1546    ) -> I32Query<'a, C, i32, 12> {
1547        I32Query {
1548            client,
1549            params: [
1550                slug,
1551                external_id,
1552                number,
1553                name,
1554                description,
1555                core,
1556                country_of_origin,
1557                tariff_no,
1558                net_weight,
1559                gross_weight,
1560                unit_volume,
1561                id,
1562            ],
1563            stmt: &mut self.0,
1564            extractor: |row| row.get(0),
1565            mapper: |it| it,
1566        }
1567    }
1568}
1569impl<
1570        'a,
1571        C: GenericClient,
1572        T1: crate::StringSql,
1573        T2: crate::StringSql,
1574        T3: crate::StringSql,
1575        T4: crate::JsonSql,
1576        T5: crate::JsonSql,
1577        T6: crate::StringSql,
1578        T7: crate::StringSql,
1579    >
1580    crate::client::async_::Params<
1581        'a,
1582        UpdateStyleParams<T1, T2, T3, T4, T5, T6, T7>,
1583        I32Query<'a, C, i32, 12>,
1584        C,
1585    > for UpdateStyleStmt
1586{
1587    fn params(
1588        &'a mut self,
1589        client: &'a C,
1590        params: &'a UpdateStyleParams<T1, T2, T3, T4, T5, T6, T7>,
1591    ) -> I32Query<'a, C, i32, 12> {
1592        self.bind(
1593            client,
1594            &params.slug,
1595            &params.external_id,
1596            &params.number,
1597            &params.name,
1598            &params.description,
1599            &params.core,
1600            &params.country_of_origin,
1601            &params.tariff_no,
1602            &params.net_weight,
1603            &params.gross_weight,
1604            &params.unit_volume,
1605            &params.id,
1606        )
1607    }
1608}
1609pub fn delete_style() -> DeleteStyleStmt {
1610    DeleteStyleStmt(crate::client::async_::Stmt::new(
1611        "DELETE FROM
1612style
1613WHERE
1614    organization_id = $1
1615    AND id = $2
1616RETURNING
1617id",
1618    ))
1619}
1620pub struct DeleteStyleStmt(crate::client::async_::Stmt);
1621impl DeleteStyleStmt {
1622    pub fn bind<'a, C: GenericClient>(
1623        &'a mut self,
1624        client: &'a C,
1625        organization_id: &'a i32,
1626        id: &'a i32,
1627    ) -> I32Query<'a, C, i32, 2> {
1628        I32Query {
1629            client,
1630            params: [organization_id, id],
1631            stmt: &mut self.0,
1632            extractor: |row| row.get(0),
1633            mapper: |it| it,
1634        }
1635    }
1636}
1637impl<'a, C: GenericClient>
1638    crate::client::async_::Params<'a, DeleteStyleParams, I32Query<'a, C, i32, 2>, C>
1639    for DeleteStyleStmt
1640{
1641    fn params(
1642        &'a mut self,
1643        client: &'a C,
1644        params: &'a DeleteStyleParams,
1645    ) -> I32Query<'a, C, i32, 2> {
1646        self.bind(client, &params.organization_id, &params.id)
1647    }
1648}