samling_clorinde/queries/
collection.rs

1// This file was generated with `clorinde`. Do not modify.
2
3#[derive(Debug)]
4pub struct SelectCollectionsParams<T1: crate::StringSql, T2: crate::StringSql> {
5    pub requester_id: i32,
6    pub organization_id: i32,
7    pub id: Option<i32>,
8    pub external_id: Option<T1>,
9    pub slug: Option<T2>,
10}
11#[derive(Debug)]
12pub struct SelectCollectionSummariesParams<T1: crate::StringSql, T2: crate::StringSql> {
13    pub requester_id: i32,
14    pub organization_id: i32,
15    pub id: Option<i32>,
16    pub external_id: Option<T1>,
17    pub slug: Option<T2>,
18}
19#[derive(Debug)]
20pub struct GetCollectionIdParams<T1: crate::StringSql, T2: crate::StringSql> {
21    pub organization_id: i32,
22    pub id: Option<i32>,
23    pub external_id: Option<T1>,
24    pub slug: Option<T2>,
25}
26#[derive(Debug)]
27pub struct InsertCollectionParams<
28    T1: crate::JsonSql,
29    T2: crate::JsonSql,
30    T3: crate::StringSql,
31    T4: crate::StringSql,
32    T5: crate::StringSql,
33> {
34    pub acronym: T1,
35    pub name: T2,
36    pub image_url: Option<T3>,
37    pub slug: T4,
38    pub external_id: Option<T5>,
39    pub organization_id: i32,
40    pub created_by: i32,
41}
42#[derive(Debug)]
43pub struct UpdateCollectionParams<
44    T1: crate::JsonSql,
45    T2: crate::JsonSql,
46    T3: crate::StringSql,
47    T4: crate::StringSql,
48    T5: crate::StringSql,
49> {
50    pub acronym: Option<T1>,
51    pub name: Option<T2>,
52    pub image_url: Option<T3>,
53    pub slug: Option<T4>,
54    pub external_id: Option<T5>,
55    pub id: i32,
56}
57#[derive(Clone, Copy, Debug)]
58pub struct DeleteCollectionParams {
59    pub organization_id: i32,
60    pub id: i32,
61}
62#[derive(Debug)]
63pub struct AssociateCollectionSizesParams<T1: crate::ArraySql<Item = i32>> {
64    pub collection_id: i32,
65    pub size_ids: T1,
66}
67#[derive(Debug)]
68pub struct ReplaceCollectionPricelistsParams<
69    T1: crate::ArraySql<Item = crate::types::CollectionPricelistRelation>,
70> {
71    pub collection_id: i32,
72    pub collection_pricelist_relations: T1,
73}
74#[derive(Debug)]
75pub struct SetNewCollectionStylesParams<T1: crate::ArraySql<Item = i32>> {
76    pub collection_id: i32,
77    pub style_ids: T1,
78}
79#[derive(Debug)]
80pub struct SetNewCollectionColorsParams<T1: crate::ArraySql<Item = i32>> {
81    pub collection_id: i32,
82    pub color_ids: T1,
83}
84#[derive(Debug, Clone, PartialEq)]
85pub struct CollectionRow {
86    pub id: i32,
87    pub organization_id: i32,
88    pub slug: String,
89    pub external_id: Option<String>,
90    pub name: serde_json::Value,
91    pub created_by: Option<i32>,
92    pub created_at: chrono::DateTime<chrono::FixedOffset>,
93    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
94    pub image_url: Option<String>,
95    pub acronym: serde_json::Value,
96    pub pricing: serde_json::Value,
97    pub sizes: serde_json::Value,
98}
99pub struct CollectionRowBorrowed<'a> {
100    pub id: i32,
101    pub organization_id: i32,
102    pub slug: &'a str,
103    pub external_id: Option<&'a str>,
104    pub name: postgres_types::Json<&'a serde_json::value::RawValue>,
105    pub created_by: Option<i32>,
106    pub created_at: chrono::DateTime<chrono::FixedOffset>,
107    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
108    pub image_url: Option<&'a str>,
109    pub acronym: postgres_types::Json<&'a serde_json::value::RawValue>,
110    pub pricing: postgres_types::Json<&'a serde_json::value::RawValue>,
111    pub sizes: postgres_types::Json<&'a serde_json::value::RawValue>,
112}
113impl<'a> From<CollectionRowBorrowed<'a>> for CollectionRow {
114    fn from(
115        CollectionRowBorrowed {
116            id,
117            organization_id,
118            slug,
119            external_id,
120            name,
121            created_by,
122            created_at,
123            updated_at,
124            image_url,
125            acronym,
126            pricing,
127            sizes,
128        }: CollectionRowBorrowed<'a>,
129    ) -> Self {
130        Self {
131            id,
132            organization_id,
133            slug: slug.into(),
134            external_id: external_id.map(|v| v.into()),
135            name: serde_json::from_str(name.0.get()).unwrap(),
136            created_by,
137            created_at,
138            updated_at,
139            image_url: image_url.map(|v| v.into()),
140            acronym: serde_json::from_str(acronym.0.get()).unwrap(),
141            pricing: serde_json::from_str(pricing.0.get()).unwrap(),
142            sizes: serde_json::from_str(sizes.0.get()).unwrap(),
143        }
144    }
145}
146#[derive(Debug, Clone, PartialEq)]
147pub struct CollectionSummaryRow {
148    pub id: i32,
149    pub organization_id: i32,
150    pub slug: String,
151    pub external_id: Option<String>,
152    pub name: serde_json::Value,
153    pub created_by: Option<i32>,
154    pub created_at: chrono::DateTime<chrono::FixedOffset>,
155    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
156    pub image_url: Option<String>,
157    pub acronym: serde_json::Value,
158    pub num_sizes: i64,
159    pub num_colors: i64,
160    pub num_styles: i64,
161    pub pricing: serde_json::Value,
162}
163pub struct CollectionSummaryRowBorrowed<'a> {
164    pub id: i32,
165    pub organization_id: i32,
166    pub slug: &'a str,
167    pub external_id: Option<&'a str>,
168    pub name: postgres_types::Json<&'a serde_json::value::RawValue>,
169    pub created_by: Option<i32>,
170    pub created_at: chrono::DateTime<chrono::FixedOffset>,
171    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
172    pub image_url: Option<&'a str>,
173    pub acronym: postgres_types::Json<&'a serde_json::value::RawValue>,
174    pub num_sizes: i64,
175    pub num_colors: i64,
176    pub num_styles: i64,
177    pub pricing: postgres_types::Json<&'a serde_json::value::RawValue>,
178}
179impl<'a> From<CollectionSummaryRowBorrowed<'a>> for CollectionSummaryRow {
180    fn from(
181        CollectionSummaryRowBorrowed {
182            id,
183            organization_id,
184            slug,
185            external_id,
186            name,
187            created_by,
188            created_at,
189            updated_at,
190            image_url,
191            acronym,
192            num_sizes,
193            num_colors,
194            num_styles,
195            pricing,
196        }: CollectionSummaryRowBorrowed<'a>,
197    ) -> Self {
198        Self {
199            id,
200            organization_id,
201            slug: slug.into(),
202            external_id: external_id.map(|v| v.into()),
203            name: serde_json::from_str(name.0.get()).unwrap(),
204            created_by,
205            created_at,
206            updated_at,
207            image_url: image_url.map(|v| v.into()),
208            acronym: serde_json::from_str(acronym.0.get()).unwrap(),
209            num_sizes,
210            num_colors,
211            num_styles,
212            pricing: serde_json::from_str(pricing.0.get()).unwrap(),
213        }
214    }
215}
216use crate::client::async_::GenericClient;
217use futures::{self, StreamExt, TryStreamExt};
218pub struct CollectionRowQuery<'a, C: GenericClient, T, const N: usize> {
219    client: &'a C,
220    params: [&'a (dyn postgres_types::ToSql + Sync); N],
221    stmt: &'a mut crate::client::async_::Stmt,
222    extractor: fn(&tokio_postgres::Row) -> CollectionRowBorrowed,
223    mapper: fn(CollectionRowBorrowed) -> T,
224}
225impl<'a, C, T: 'a, const N: usize> CollectionRowQuery<'a, C, T, N>
226where
227    C: GenericClient,
228{
229    pub fn map<R>(self, mapper: fn(CollectionRowBorrowed) -> R) -> CollectionRowQuery<'a, C, R, N> {
230        CollectionRowQuery {
231            client: self.client,
232            params: self.params,
233            stmt: self.stmt,
234            extractor: self.extractor,
235            mapper,
236        }
237    }
238    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
239        let stmt = self.stmt.prepare(self.client).await?;
240        let row = self.client.query_one(stmt, &self.params).await?;
241        Ok((self.mapper)((self.extractor)(&row)))
242    }
243    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
244        self.iter().await?.try_collect().await
245    }
246    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
247        let stmt = self.stmt.prepare(self.client).await?;
248        Ok(self
249            .client
250            .query_opt(stmt, &self.params)
251            .await?
252            .map(|row| (self.mapper)((self.extractor)(&row))))
253    }
254    pub async fn iter(
255        self,
256    ) -> Result<
257        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
258        tokio_postgres::Error,
259    > {
260        let stmt = self.stmt.prepare(self.client).await?;
261        let it = self
262            .client
263            .query_raw(stmt, crate::slice_iter(&self.params))
264            .await?
265            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
266            .into_stream();
267        Ok(it)
268    }
269}
270pub struct CollectionSummaryRowQuery<'a, C: GenericClient, T, const N: usize> {
271    client: &'a C,
272    params: [&'a (dyn postgres_types::ToSql + Sync); N],
273    stmt: &'a mut crate::client::async_::Stmt,
274    extractor: fn(&tokio_postgres::Row) -> CollectionSummaryRowBorrowed,
275    mapper: fn(CollectionSummaryRowBorrowed) -> T,
276}
277impl<'a, C, T: 'a, const N: usize> CollectionSummaryRowQuery<'a, C, T, N>
278where
279    C: GenericClient,
280{
281    pub fn map<R>(
282        self,
283        mapper: fn(CollectionSummaryRowBorrowed) -> R,
284    ) -> CollectionSummaryRowQuery<'a, C, R, N> {
285        CollectionSummaryRowQuery {
286            client: self.client,
287            params: self.params,
288            stmt: self.stmt,
289            extractor: self.extractor,
290            mapper,
291        }
292    }
293    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
294        let stmt = self.stmt.prepare(self.client).await?;
295        let row = self.client.query_one(stmt, &self.params).await?;
296        Ok((self.mapper)((self.extractor)(&row)))
297    }
298    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
299        self.iter().await?.try_collect().await
300    }
301    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
302        let stmt = self.stmt.prepare(self.client).await?;
303        Ok(self
304            .client
305            .query_opt(stmt, &self.params)
306            .await?
307            .map(|row| (self.mapper)((self.extractor)(&row))))
308    }
309    pub async fn iter(
310        self,
311    ) -> Result<
312        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
313        tokio_postgres::Error,
314    > {
315        let stmt = self.stmt.prepare(self.client).await?;
316        let it = self
317            .client
318            .query_raw(stmt, crate::slice_iter(&self.params))
319            .await?
320            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
321            .into_stream();
322        Ok(it)
323    }
324}
325pub struct I32Query<'a, C: GenericClient, T, const N: usize> {
326    client: &'a C,
327    params: [&'a (dyn postgres_types::ToSql + Sync); N],
328    stmt: &'a mut crate::client::async_::Stmt,
329    extractor: fn(&tokio_postgres::Row) -> i32,
330    mapper: fn(i32) -> T,
331}
332impl<'a, C, T: 'a, const N: usize> I32Query<'a, C, T, N>
333where
334    C: GenericClient,
335{
336    pub fn map<R>(self, mapper: fn(i32) -> R) -> I32Query<'a, C, R, N> {
337        I32Query {
338            client: self.client,
339            params: self.params,
340            stmt: self.stmt,
341            extractor: self.extractor,
342            mapper,
343        }
344    }
345    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
346        let stmt = self.stmt.prepare(self.client).await?;
347        let row = self.client.query_one(stmt, &self.params).await?;
348        Ok((self.mapper)((self.extractor)(&row)))
349    }
350    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
351        self.iter().await?.try_collect().await
352    }
353    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
354        let stmt = self.stmt.prepare(self.client).await?;
355        Ok(self
356            .client
357            .query_opt(stmt, &self.params)
358            .await?
359            .map(|row| (self.mapper)((self.extractor)(&row))))
360    }
361    pub async fn iter(
362        self,
363    ) -> Result<
364        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
365        tokio_postgres::Error,
366    > {
367        let stmt = self.stmt.prepare(self.client).await?;
368        let it = self
369            .client
370            .query_raw(stmt, crate::slice_iter(&self.params))
371            .await?
372            .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
373            .into_stream();
374        Ok(it)
375    }
376}
377pub fn select_collections() -> SelectCollectionsStmt {
378    SelectCollectionsStmt(crate::client::async_::Stmt::new(
379        "SELECT
380    collection.*,
381    coalesce(pricing.json_data, '[]'::json) AS pricing,
382    coalesce(sizes.json_data, '[]'::json) AS sizes
383FROM
384    collection
385INNER JOIN (
386    SELECT group_collection.collection_id
387    FROM group_collection
388    INNER JOIN group_user
389        ON group_user.group_id = group_collection.group_id
390    WHERE
391        group_user.user_id = $1
392    GROUP BY group_collection.collection_id
393    UNION
394    SELECT collection.id AS collection_id
395    FROM collection
396    WHERE collection.created_by = $1
397) AS requester_collections ON requester_collections.collection_id = collection.id
398LEFT JOIN (
399    SELECT
400        size_collection.collection_id,
401        json_agg(
402            size.* ORDER BY size_collection.position
403        ) FILTER (WHERE size.id IS NOT NULL) AS json_data
404    FROM size
405    INNER JOIN size_collection ON size_collection.size_id = size.id
406    GROUP BY size_collection.collection_id
407) AS sizes ON sizes.collection_id = collection.id
408LEFT JOIN LATERAL (
409    SELECT
410        collection_pricelist.collection_id,
411        json_agg(
412            json_build_object(
413                'list',
414                json_build_object(
415                    'id',
416                    pricelist.id,
417                    'external_id',
418                    pricelist.external_id,
419                    'slug',
420                    pricelist.slug,
421                    'name',
422                    pricelist.name
423                ),
424                'date',
425                collection_pricelist.price_date
426            )
427        ) FILTER (WHERE collection_pricelist.collection_id IS NOT NULL) AS json_data
428    FROM collection_pricelist
429    INNER JOIN pricelist
430        ON pricelist.id = collection_pricelist.pricelist_id
431    WHERE collection_pricelist.collection_id = collection.id
432    GROUP BY collection_pricelist.collection_id
433) AS pricing ON pricing.collection_id = collection.id
434WHERE
435    collection.organization_id = $2
436    AND ($3::int IS NULL OR collection.id = $3)
437    AND ($4::text IS NULL OR collection.external_id = $4)
438    AND ($5::text IS NULL OR collection.slug = $5)
439ORDER BY
440    collection.updated_at DESC",
441    ))
442}
443pub struct SelectCollectionsStmt(crate::client::async_::Stmt);
444impl SelectCollectionsStmt {
445    pub fn bind<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>(
446        &'a mut self,
447        client: &'a C,
448        requester_id: &'a i32,
449        organization_id: &'a i32,
450        id: &'a Option<i32>,
451        external_id: &'a Option<T1>,
452        slug: &'a Option<T2>,
453    ) -> CollectionRowQuery<'a, C, CollectionRow, 5> {
454        CollectionRowQuery {
455            client,
456            params: [requester_id, organization_id, id, external_id, slug],
457            stmt: &mut self.0,
458            extractor: |row| CollectionRowBorrowed {
459                id: row.get(0),
460                organization_id: row.get(1),
461                slug: row.get(2),
462                external_id: row.get(3),
463                name: row.get(4),
464                created_by: row.get(5),
465                created_at: row.get(6),
466                updated_at: row.get(7),
467                image_url: row.get(8),
468                acronym: row.get(9),
469                pricing: row.get(10),
470                sizes: row.get(11),
471            },
472            mapper: |it| <CollectionRow>::from(it),
473        }
474    }
475}
476impl<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>
477    crate::client::async_::Params<
478        'a,
479        SelectCollectionsParams<T1, T2>,
480        CollectionRowQuery<'a, C, CollectionRow, 5>,
481        C,
482    > for SelectCollectionsStmt
483{
484    fn params(
485        &'a mut self,
486        client: &'a C,
487        params: &'a SelectCollectionsParams<T1, T2>,
488    ) -> CollectionRowQuery<'a, C, CollectionRow, 5> {
489        self.bind(
490            client,
491            &params.requester_id,
492            &params.organization_id,
493            &params.id,
494            &params.external_id,
495            &params.slug,
496        )
497    }
498}
499pub fn select_collection_summaries() -> SelectCollectionSummariesStmt {
500    SelectCollectionSummariesStmt(crate::client::async_::Stmt::new(
501        "SELECT
502    collection.*,
503    coalesce(stats.num_sizes, 0) AS num_sizes,
504    coalesce(stats.num_colors, 0) AS num_colors,
505    coalesce(stats.num_styles, 0) AS num_styles,
506    coalesce(pricing.json_data, '[]'::json) AS pricing
507FROM
508    collection
509INNER JOIN (
510    SELECT group_collection.collection_id
511    FROM group_collection
512    INNER JOIN group_user
513        ON group_user.group_id = group_collection.group_id
514    WHERE
515        group_user.user_id = $1
516    GROUP BY group_collection.collection_id
517    UNION
518    SELECT collection.id AS collection_id
519    FROM collection
520    WHERE collection.created_by = $1
521) AS requester_collections ON requester_collections.collection_id = collection.id
522LEFT JOIN (
523    SELECT
524        size_collection.collection_id,
525        count(DISTINCT size.id) AS num_sizes,
526        count(DISTINCT color.id) AS num_colors,
527        count(DISTINCT color.style_id) AS num_styles
528    FROM color
529    INNER JOIN size ON size.color_id = color.id
530    INNER JOIN size_collection ON size.id = size_collection.size_id
531    GROUP BY size_collection.collection_id
532) AS stats ON stats.collection_id = collection.id
533LEFT JOIN LATERAL (
534    SELECT
535        collection_pricelist.collection_id,
536        json_agg(
537            json_build_object(
538                'list',
539                json_build_object(
540                    'id',
541                    pricelist.id,
542                    'external_id',
543                    pricelist.external_id,
544                    'slug',
545                    pricelist.slug,
546                    'name',
547                    pricelist.name
548                ),
549                'date',
550                collection_pricelist.price_date
551            )
552        ) FILTER (WHERE collection_pricelist.collection_id IS NOT NULL) AS json_data,
553        min(collection_pricelist.price_date) AS min_price_date
554    FROM collection_pricelist
555    INNER JOIN pricelist
556        ON pricelist.id = collection_pricelist.pricelist_id
557    WHERE collection_pricelist.collection_id = collection.id
558    GROUP BY collection_pricelist.collection_id
559) AS pricing ON pricing.collection_id = collection.id
560WHERE
561    collection.organization_id = $2
562    AND ($3::int IS NULL OR collection.id = $3)
563    AND ($4::text IS NULL OR collection.external_id = $4)
564    AND ($5::text IS NULL OR collection.slug = $5)
565ORDER BY
566    pricing.min_price_date DESC, collection.name ASC",
567    ))
568}
569pub struct SelectCollectionSummariesStmt(crate::client::async_::Stmt);
570impl SelectCollectionSummariesStmt {
571    pub fn bind<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>(
572        &'a mut self,
573        client: &'a C,
574        requester_id: &'a i32,
575        organization_id: &'a i32,
576        id: &'a Option<i32>,
577        external_id: &'a Option<T1>,
578        slug: &'a Option<T2>,
579    ) -> CollectionSummaryRowQuery<'a, C, CollectionSummaryRow, 5> {
580        CollectionSummaryRowQuery {
581            client,
582            params: [requester_id, organization_id, id, external_id, slug],
583            stmt: &mut self.0,
584            extractor: |row| CollectionSummaryRowBorrowed {
585                id: row.get(0),
586                organization_id: row.get(1),
587                slug: row.get(2),
588                external_id: row.get(3),
589                name: row.get(4),
590                created_by: row.get(5),
591                created_at: row.get(6),
592                updated_at: row.get(7),
593                image_url: row.get(8),
594                acronym: row.get(9),
595                num_sizes: row.get(10),
596                num_colors: row.get(11),
597                num_styles: row.get(12),
598                pricing: row.get(13),
599            },
600            mapper: |it| <CollectionSummaryRow>::from(it),
601        }
602    }
603}
604impl<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>
605    crate::client::async_::Params<
606        'a,
607        SelectCollectionSummariesParams<T1, T2>,
608        CollectionSummaryRowQuery<'a, C, CollectionSummaryRow, 5>,
609        C,
610    > for SelectCollectionSummariesStmt
611{
612    fn params(
613        &'a mut self,
614        client: &'a C,
615        params: &'a SelectCollectionSummariesParams<T1, T2>,
616    ) -> CollectionSummaryRowQuery<'a, C, CollectionSummaryRow, 5> {
617        self.bind(
618            client,
619            &params.requester_id,
620            &params.organization_id,
621            &params.id,
622            &params.external_id,
623            &params.slug,
624        )
625    }
626}
627pub fn get_collection_id() -> GetCollectionIdStmt {
628    GetCollectionIdStmt(crate::client::async_::Stmt::new(
629        "SELECT collection.id
630FROM
631    collection
632WHERE
633    collection.organization_id = $1
634    AND ($2::int IS NULL OR collection.id = $2)
635    AND ($3::text IS NULL OR collection.external_id = $3)
636    AND ($4::text IS NULL OR collection.slug = $4)",
637    ))
638}
639pub struct GetCollectionIdStmt(crate::client::async_::Stmt);
640impl GetCollectionIdStmt {
641    pub fn bind<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>(
642        &'a mut self,
643        client: &'a C,
644        organization_id: &'a i32,
645        id: &'a Option<i32>,
646        external_id: &'a Option<T1>,
647        slug: &'a Option<T2>,
648    ) -> I32Query<'a, C, i32, 4> {
649        I32Query {
650            client,
651            params: [organization_id, id, external_id, slug],
652            stmt: &mut self.0,
653            extractor: |row| row.get(0),
654            mapper: |it| it,
655        }
656    }
657}
658impl<'a, C: GenericClient, T1: crate::StringSql, T2: crate::StringSql>
659    crate::client::async_::Params<'a, GetCollectionIdParams<T1, T2>, I32Query<'a, C, i32, 4>, C>
660    for GetCollectionIdStmt
661{
662    fn params(
663        &'a mut self,
664        client: &'a C,
665        params: &'a GetCollectionIdParams<T1, T2>,
666    ) -> I32Query<'a, C, i32, 4> {
667        self.bind(
668            client,
669            &params.organization_id,
670            &params.id,
671            &params.external_id,
672            &params.slug,
673        )
674    }
675}
676pub fn insert_collection() -> InsertCollectionStmt {
677    InsertCollectionStmt(crate::client::async_::Stmt::new(
678        "INSERT INTO collection (
679    acronym,
680    name,
681    image_url,
682    slug,
683    external_id,
684    organization_id,
685    created_by)
686VALUES (
687    $1,
688    $2,
689    $3,
690    $4,
691    $5,
692    $6,
693    $7)
694RETURNING
695id",
696    ))
697}
698pub struct InsertCollectionStmt(crate::client::async_::Stmt);
699impl InsertCollectionStmt {
700    pub fn bind<
701        'a,
702        C: GenericClient,
703        T1: crate::JsonSql,
704        T2: crate::JsonSql,
705        T3: crate::StringSql,
706        T4: crate::StringSql,
707        T5: crate::StringSql,
708    >(
709        &'a mut self,
710        client: &'a C,
711        acronym: &'a T1,
712        name: &'a T2,
713        image_url: &'a Option<T3>,
714        slug: &'a T4,
715        external_id: &'a Option<T5>,
716        organization_id: &'a i32,
717        created_by: &'a i32,
718    ) -> I32Query<'a, C, i32, 7> {
719        I32Query {
720            client,
721            params: [
722                acronym,
723                name,
724                image_url,
725                slug,
726                external_id,
727                organization_id,
728                created_by,
729            ],
730            stmt: &mut self.0,
731            extractor: |row| row.get(0),
732            mapper: |it| it,
733        }
734    }
735}
736impl<
737        'a,
738        C: GenericClient,
739        T1: crate::JsonSql,
740        T2: crate::JsonSql,
741        T3: crate::StringSql,
742        T4: crate::StringSql,
743        T5: crate::StringSql,
744    >
745    crate::client::async_::Params<
746        'a,
747        InsertCollectionParams<T1, T2, T3, T4, T5>,
748        I32Query<'a, C, i32, 7>,
749        C,
750    > for InsertCollectionStmt
751{
752    fn params(
753        &'a mut self,
754        client: &'a C,
755        params: &'a InsertCollectionParams<T1, T2, T3, T4, T5>,
756    ) -> I32Query<'a, C, i32, 7> {
757        self.bind(
758            client,
759            &params.acronym,
760            &params.name,
761            &params.image_url,
762            &params.slug,
763            &params.external_id,
764            &params.organization_id,
765            &params.created_by,
766        )
767    }
768}
769pub fn update_collection() -> UpdateCollectionStmt {
770    UpdateCollectionStmt(crate::client::async_::Stmt::new(
771        "UPDATE
772collection
773SET
774    acronym = coalesce($1, acronym),
775    name = coalesce($2, name),
776    image_url = coalesce($3, image_url),
777    slug = coalesce($4, slug),
778    external_id = coalesce($5, external_id)
779WHERE
780    id = $6",
781    ))
782}
783pub struct UpdateCollectionStmt(crate::client::async_::Stmt);
784impl UpdateCollectionStmt {
785    pub async fn bind<
786        'a,
787        C: GenericClient,
788        T1: crate::JsonSql,
789        T2: crate::JsonSql,
790        T3: crate::StringSql,
791        T4: crate::StringSql,
792        T5: crate::StringSql,
793    >(
794        &'a mut self,
795        client: &'a C,
796        acronym: &'a Option<T1>,
797        name: &'a Option<T2>,
798        image_url: &'a Option<T3>,
799        slug: &'a Option<T4>,
800        external_id: &'a Option<T5>,
801        id: &'a i32,
802    ) -> Result<u64, tokio_postgres::Error> {
803        let stmt = self.0.prepare(client).await?;
804        client
805            .execute(stmt, &[acronym, name, image_url, slug, external_id, id])
806            .await
807    }
808}
809impl<
810        'a,
811        C: GenericClient + Send + Sync,
812        T1: crate::JsonSql,
813        T2: crate::JsonSql,
814        T3: crate::StringSql,
815        T4: crate::StringSql,
816        T5: crate::StringSql,
817    >
818    crate::client::async_::Params<
819        'a,
820        UpdateCollectionParams<T1, T2, T3, T4, T5>,
821        std::pin::Pin<
822            Box<dyn futures::Future<Output = Result<u64, tokio_postgres::Error>> + Send + 'a>,
823        >,
824        C,
825    > for UpdateCollectionStmt
826{
827    fn params(
828        &'a mut self,
829        client: &'a C,
830        params: &'a UpdateCollectionParams<T1, T2, T3, T4, T5>,
831    ) -> std::pin::Pin<
832        Box<dyn futures::Future<Output = Result<u64, tokio_postgres::Error>> + Send + 'a>,
833    > {
834        Box::pin(self.bind(
835            client,
836            &params.acronym,
837            &params.name,
838            &params.image_url,
839            &params.slug,
840            &params.external_id,
841            &params.id,
842        ))
843    }
844}
845pub fn delete_collection() -> DeleteCollectionStmt {
846    DeleteCollectionStmt(crate::client::async_::Stmt::new(
847        "DELETE FROM collection
848WHERE organization_id = $1
849      AND id = $2",
850    ))
851}
852pub struct DeleteCollectionStmt(crate::client::async_::Stmt);
853impl DeleteCollectionStmt {
854    pub async fn bind<'a, C: GenericClient>(
855        &'a mut self,
856        client: &'a C,
857        organization_id: &'a i32,
858        id: &'a i32,
859    ) -> Result<u64, tokio_postgres::Error> {
860        let stmt = self.0.prepare(client).await?;
861        client.execute(stmt, &[organization_id, id]).await
862    }
863}
864impl<'a, C: GenericClient + Send + Sync>
865    crate::client::async_::Params<
866        'a,
867        DeleteCollectionParams,
868        std::pin::Pin<
869            Box<dyn futures::Future<Output = Result<u64, tokio_postgres::Error>> + Send + 'a>,
870        >,
871        C,
872    > for DeleteCollectionStmt
873{
874    fn params(
875        &'a mut self,
876        client: &'a C,
877        params: &'a DeleteCollectionParams,
878    ) -> std::pin::Pin<
879        Box<dyn futures::Future<Output = Result<u64, tokio_postgres::Error>> + Send + 'a>,
880    > {
881        Box::pin(self.bind(client, &params.organization_id, &params.id))
882    }
883}
884pub fn associate_collection_sizes() -> AssociateCollectionSizesStmt {
885    AssociateCollectionSizesStmt(crate::client::async_::Stmt::new(
886        "SELECT *
887FROM
888    associate_collection_sizes($1, $2)",
889    ))
890}
891pub struct AssociateCollectionSizesStmt(crate::client::async_::Stmt);
892impl AssociateCollectionSizesStmt {
893    pub fn bind<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>(
894        &'a mut self,
895        client: &'a C,
896        collection_id: &'a i32,
897        size_ids: &'a T1,
898    ) -> I32Query<'a, C, i32, 2> {
899        I32Query {
900            client,
901            params: [collection_id, size_ids],
902            stmt: &mut self.0,
903            extractor: |row| row.get(0),
904            mapper: |it| it,
905        }
906    }
907}
908impl<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>
909    crate::client::async_::Params<
910        'a,
911        AssociateCollectionSizesParams<T1>,
912        I32Query<'a, C, i32, 2>,
913        C,
914    > for AssociateCollectionSizesStmt
915{
916    fn params(
917        &'a mut self,
918        client: &'a C,
919        params: &'a AssociateCollectionSizesParams<T1>,
920    ) -> I32Query<'a, C, i32, 2> {
921        self.bind(client, &params.collection_id, &params.size_ids)
922    }
923}
924pub fn replace_collection_pricelists() -> ReplaceCollectionPricelistsStmt {
925    ReplaceCollectionPricelistsStmt(crate::client::async_::Stmt::new(
926        "SELECT *
927FROM
928    replace_collection_pricelists($1, $2)",
929    ))
930}
931pub struct ReplaceCollectionPricelistsStmt(crate::client::async_::Stmt);
932impl ReplaceCollectionPricelistsStmt {
933    pub fn bind<
934        'a,
935        C: GenericClient,
936        T1: crate::ArraySql<Item = crate::types::CollectionPricelistRelation>,
937    >(
938        &'a mut self,
939        client: &'a C,
940        collection_id: &'a i32,
941        collection_pricelist_relations: &'a T1,
942    ) -> I32Query<'a, C, i32, 2> {
943        I32Query {
944            client,
945            params: [collection_id, collection_pricelist_relations],
946            stmt: &mut self.0,
947            extractor: |row| row.get(0),
948            mapper: |it| it,
949        }
950    }
951}
952impl<
953        'a,
954        C: GenericClient,
955        T1: crate::ArraySql<Item = crate::types::CollectionPricelistRelation>,
956    >
957    crate::client::async_::Params<
958        'a,
959        ReplaceCollectionPricelistsParams<T1>,
960        I32Query<'a, C, i32, 2>,
961        C,
962    > for ReplaceCollectionPricelistsStmt
963{
964    fn params(
965        &'a mut self,
966        client: &'a C,
967        params: &'a ReplaceCollectionPricelistsParams<T1>,
968    ) -> I32Query<'a, C, i32, 2> {
969        self.bind(
970            client,
971            &params.collection_id,
972            &params.collection_pricelist_relations,
973        )
974    }
975}
976pub fn set_new_collection_styles() -> SetNewCollectionStylesStmt {
977    SetNewCollectionStylesStmt(crate::client::async_::Stmt::new(
978        "SELECT *
979FROM
980    set_new_collection_styles($1, $2)",
981    ))
982}
983pub struct SetNewCollectionStylesStmt(crate::client::async_::Stmt);
984impl SetNewCollectionStylesStmt {
985    pub fn bind<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>(
986        &'a mut self,
987        client: &'a C,
988        collection_id: &'a i32,
989        style_ids: &'a T1,
990    ) -> I32Query<'a, C, i32, 2> {
991        I32Query {
992            client,
993            params: [collection_id, style_ids],
994            stmt: &mut self.0,
995            extractor: |row| row.get(0),
996            mapper: |it| it,
997        }
998    }
999}
1000impl<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>
1001    crate::client::async_::Params<'a, SetNewCollectionStylesParams<T1>, I32Query<'a, C, i32, 2>, C>
1002    for SetNewCollectionStylesStmt
1003{
1004    fn params(
1005        &'a mut self,
1006        client: &'a C,
1007        params: &'a SetNewCollectionStylesParams<T1>,
1008    ) -> I32Query<'a, C, i32, 2> {
1009        self.bind(client, &params.collection_id, &params.style_ids)
1010    }
1011}
1012pub fn set_new_collection_colors() -> SetNewCollectionColorsStmt {
1013    SetNewCollectionColorsStmt(crate::client::async_::Stmt::new(
1014        "SELECT *
1015FROM
1016    set_new_collection_colors($1, $2)",
1017    ))
1018}
1019pub struct SetNewCollectionColorsStmt(crate::client::async_::Stmt);
1020impl SetNewCollectionColorsStmt {
1021    pub fn bind<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>(
1022        &'a mut self,
1023        client: &'a C,
1024        collection_id: &'a i32,
1025        color_ids: &'a T1,
1026    ) -> I32Query<'a, C, i32, 2> {
1027        I32Query {
1028            client,
1029            params: [collection_id, color_ids],
1030            stmt: &mut self.0,
1031            extractor: |row| row.get(0),
1032            mapper: |it| it,
1033        }
1034    }
1035}
1036impl<'a, C: GenericClient, T1: crate::ArraySql<Item = i32>>
1037    crate::client::async_::Params<'a, SetNewCollectionColorsParams<T1>, I32Query<'a, C, i32, 2>, C>
1038    for SetNewCollectionColorsStmt
1039{
1040    fn params(
1041        &'a mut self,
1042        client: &'a C,
1043        params: &'a SetNewCollectionColorsParams<T1>,
1044    ) -> I32Query<'a, C, i32, 2> {
1045        self.bind(client, &params.collection_id, &params.color_ids)
1046    }
1047}