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