sea_query/extension/postgres/func.rs
1//! For calling built-in Postgres SQL functions.
2
3use crate::{PgDateTruncUnit, expr::*, func::*};
4
5pub mod json_exists;
6pub mod json_fn;
7pub mod json_query;
8pub mod json_table;
9pub mod json_value;
10
11/// Known Postgres-specific functions.
12///
13/// For all supported functions (including the standard ones), see [`Function`].
14///
15/// If something is not supported, you can use [`Function::Custom`].
16#[derive(Debug, Clone, PartialEq)]
17#[non_exhaustive]
18pub enum PgFunc {
19 ToTsquery,
20 ToTsvector,
21 PhrasetoTsquery,
22 PlaintoTsquery,
23 WebsearchToTsquery,
24 TsRank,
25 TsRankCd,
26 StartsWith,
27 GenRandomUUID,
28 JsonBuildObject,
29 JsonAgg,
30 ArrayAgg,
31 DateTrunc,
32 Any,
33 Some,
34 All,
35 AdvisoryLock,
36 AdvisoryLockShared,
37 TryAdvisoryLock,
38 TryAdvisoryLockShared,
39 AdvisoryUnlock,
40 AdvisoryUnlockShared,
41 AdvisoryUnlockAll,
42 AdvisoryXactLock,
43 AdvisoryXactLockShared,
44 TryAdvisoryXactLock,
45 TryAdvisoryXactLockShared,
46}
47
48impl From<PgFunc> for Func {
49 fn from(func: PgFunc) -> Self {
50 Self::PgFunction(func)
51 }
52}
53
54/// Type alias of [`PgFunc`] for compatibility.
55/// Previously, [`PgFunc`] is a namespace for building [`FunctionCall`].
56#[deprecated(since = "1.0.0", note = "use `PgFunc` instead")]
57pub type PgFunction = PgFunc;
58
59impl PgFunc {
60 /// Call `TO_TSQUERY` function. Postgres only.
61 ///
62 /// The parameter `regconfig` represents the OID of the text search configuration.
63 /// If the value is `None` the argument is omitted from the query, and hence the database default used.
64 ///
65 /// # Examples
66 ///
67 /// ```
68 /// use sea_query::{tests_cfg::*, *};
69 ///
70 /// let query = Query::select()
71 /// .expr(PgFunc::to_tsquery("a & b", None))
72 /// .to_owned();
73 ///
74 /// assert_eq!(
75 /// query.to_string(PostgresQueryBuilder),
76 /// r#"SELECT TO_TSQUERY('a & b')"#
77 /// );
78 /// ```
79 pub fn to_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
80 where
81 T: Into<Expr>,
82 {
83 match regconfig {
84 Some(config) => {
85 let config = Expr::Value(config.into());
86 FunctionCall::new(PgFunc::ToTsquery).args([config, expr.into()])
87 }
88 None => FunctionCall::new(PgFunc::ToTsquery).arg(expr),
89 }
90 }
91
92 /// Call `TO_TSVECTOR` function. Postgres only.
93 ///
94 /// The parameter `regconfig` represents the OID of the text search configuration.
95 /// If the value is `None` the argument is omitted from the query, and hence the database default used.
96 ///
97 /// # Examples
98 ///
99 /// ```
100 /// use sea_query::{tests_cfg::*, *};
101 ///
102 /// let query = Query::select()
103 /// .expr(PgFunc::to_tsvector("a b", None))
104 /// .to_owned();
105 ///
106 /// assert_eq!(
107 /// query.to_string(PostgresQueryBuilder),
108 /// r#"SELECT TO_TSVECTOR('a b')"#
109 /// );
110 /// ```
111 pub fn to_tsvector<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
112 where
113 T: Into<Expr>,
114 {
115 match regconfig {
116 Some(config) => {
117 let config = Expr::Value(config.into());
118 FunctionCall::new(PgFunc::ToTsvector).args([config, expr.into()])
119 }
120 None => FunctionCall::new(PgFunc::ToTsvector).arg(expr),
121 }
122 }
123
124 /// Call `PHRASE_TO_TSQUERY` function. Postgres only.
125 ///
126 /// The parameter `regconfig` represents the OID of the text search configuration.
127 /// If the value is `None` the argument is omitted from the query, and hence the database default used.
128 ///
129 /// # Examples
130 ///
131 /// ```
132 /// use sea_query::{tests_cfg::*, *};
133 ///
134 /// let query = Query::select()
135 /// .expr(PgFunc::phraseto_tsquery("a b", None))
136 /// .to_owned();
137 ///
138 /// assert_eq!(
139 /// query.to_string(PostgresQueryBuilder),
140 /// r#"SELECT PHRASETO_TSQUERY('a b')"#
141 /// );
142 /// ```
143 pub fn phraseto_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
144 where
145 T: Into<Expr>,
146 {
147 match regconfig {
148 Some(config) => {
149 let config = Expr::Value(config.into());
150 FunctionCall::new(PgFunc::PhrasetoTsquery).args([config, expr.into()])
151 }
152 None => FunctionCall::new(PgFunc::PhrasetoTsquery).arg(expr),
153 }
154 }
155
156 /// Call `PLAIN_TO_TSQUERY` function. Postgres only.
157 ///
158 /// The parameter `regconfig` represents the OID of the text search configuration.
159 /// If the value is `None` the argument is omitted from the query, and hence the database default used.
160 ///
161 /// # Examples
162 ///
163 /// ```
164 /// use sea_query::{tests_cfg::*, *};
165 ///
166 /// let query = Query::select()
167 /// .expr(PgFunc::plainto_tsquery("a b", None))
168 /// .to_owned();
169 ///
170 /// assert_eq!(
171 /// query.to_string(PostgresQueryBuilder),
172 /// r#"SELECT PLAINTO_TSQUERY('a b')"#
173 /// );
174 /// ```
175 pub fn plainto_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
176 where
177 T: Into<Expr>,
178 {
179 match regconfig {
180 Some(config) => {
181 let config = Expr::Value(config.into());
182 FunctionCall::new(PgFunc::PlaintoTsquery).args([config, expr.into()])
183 }
184 None => FunctionCall::new(PgFunc::PlaintoTsquery).arg(expr),
185 }
186 }
187
188 /// Call `WEBSEARCH_TO_TSQUERY` function. Postgres only.
189 ///
190 /// The parameter `regconfig` represents the OID of the text search configuration.
191 /// If the value is `None` the argument is omitted from the query, and hence the database default used.
192 ///
193 /// # Examples
194 ///
195 /// ```
196 /// use sea_query::{tests_cfg::*, *};
197 ///
198 /// let query = Query::select()
199 /// .expr(PgFunc::websearch_to_tsquery("a b", None))
200 /// .to_owned();
201 ///
202 /// assert_eq!(
203 /// query.to_string(PostgresQueryBuilder),
204 /// r#"SELECT WEBSEARCH_TO_TSQUERY('a b')"#
205 /// );
206 /// ```
207 pub fn websearch_to_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
208 where
209 T: Into<Expr>,
210 {
211 match regconfig {
212 Some(config) => {
213 let config = Expr::Value(config.into());
214 FunctionCall::new(PgFunc::WebsearchToTsquery).args([config, expr.into()])
215 }
216 None => FunctionCall::new(PgFunc::WebsearchToTsquery).arg(expr),
217 }
218 }
219
220 /// Call `TS_RANK` function. Postgres only.
221 ///
222 /// # Examples
223 ///
224 /// ```
225 /// use sea_query::{tests_cfg::*, *};
226 ///
227 /// let query = Query::select()
228 /// .expr(PgFunc::ts_rank("a b", "a&b"))
229 /// .to_owned();
230 ///
231 /// assert_eq!(
232 /// query.to_string(PostgresQueryBuilder),
233 /// r#"SELECT TS_RANK('a b', 'a&b')"#
234 /// );
235 /// ```
236 pub fn ts_rank<T>(vector: T, query: T) -> FunctionCall
237 where
238 T: Into<Expr>,
239 {
240 FunctionCall::new(PgFunc::TsRank).args([vector.into(), query.into()])
241 }
242
243 /// Call `TS_RANK_CD` function. Postgres only.
244 ///
245 /// # Examples
246 ///
247 /// ```
248 /// use sea_query::{tests_cfg::*, *};
249 ///
250 /// let query = Query::select()
251 /// .expr(PgFunc::ts_rank_cd("a b", "a&b"))
252 /// .to_owned();
253 ///
254 /// assert_eq!(
255 /// query.to_string(PostgresQueryBuilder),
256 /// r#"SELECT TS_RANK_CD('a b', 'a&b')"#
257 /// );
258 /// ```
259 pub fn ts_rank_cd<T>(vector: T, query: T) -> FunctionCall
260 where
261 T: Into<Expr>,
262 {
263 FunctionCall::new(PgFunc::TsRankCd).args([vector.into(), query.into()])
264 }
265
266 /// Call `ANY` function. Postgres only.
267 ///
268 /// # Examples
269 ///
270 /// ```
271 /// #[cfg(feature = "postgres-array")]
272 /// # {
273 /// use sea_query::{tests_cfg::*, *};
274 ///
275 /// let query = Query::select().expr(PgFunc::any(vec![0, 1])).to_owned();
276 ///
277 /// assert_eq!(
278 /// query.to_string(PostgresQueryBuilder),
279 /// r#"SELECT ANY(ARRAY [0,1])"#
280 /// );
281 /// # }
282 /// ```
283 /// ```
284 /// use sea_query::{tests_cfg::*, *};
285 ///
286 /// let query = Query::select()
287 /// .column("id")
288 /// .from("post")
289 /// .and_where(Expr::col("tag").eq(PgFunc::any(Expr::cust("string_to_array('a,b,c', ',')"))))
290 /// .to_owned();
291 ///
292 /// assert_eq!(
293 /// query.to_string(PostgresQueryBuilder),
294 /// r#"SELECT "id" FROM "post" WHERE "tag" = ANY(string_to_array('a,b,c', ','))"#
295 /// );
296 /// ```
297 pub fn any<T>(expr: T) -> FunctionCall
298 where
299 T: Into<Expr>,
300 {
301 FunctionCall::new(PgFunc::Any).arg(expr)
302 }
303
304 /// Call `SOME` function. Postgres only.
305 ///
306 /// # Examples
307 ///
308 /// ```
309 /// #[cfg(feature = "postgres-array")]
310 /// # {
311 /// use sea_query::{tests_cfg::*, *};
312 ///
313 /// let query = Query::select().expr(PgFunc::some(vec![0, 1])).to_owned();
314 ///
315 /// assert_eq!(
316 /// query.to_string(PostgresQueryBuilder),
317 /// r#"SELECT SOME(ARRAY [0,1])"#
318 /// );
319 /// # }
320 /// ```
321 pub fn some<T>(expr: T) -> FunctionCall
322 where
323 T: Into<Expr>,
324 {
325 FunctionCall::new(PgFunc::Some).arg(expr)
326 }
327
328 /// Call `ALL` function. Postgres only.
329 ///
330 /// # Examples
331 ///
332 /// ```
333 /// #[cfg(feature = "postgres-array")]
334 /// # {
335 /// use sea_query::{tests_cfg::*, *};
336 ///
337 /// let query = Query::select().expr(PgFunc::all(vec![0, 1])).to_owned();
338 ///
339 /// assert_eq!(
340 /// query.to_string(PostgresQueryBuilder),
341 /// r#"SELECT ALL(ARRAY [0,1])"#
342 /// );
343 /// # }
344 /// ```
345 pub fn all<T>(expr: T) -> FunctionCall
346 where
347 T: Into<Expr>,
348 {
349 FunctionCall::new(PgFunc::All).arg(expr)
350 }
351
352 /// Call `STARTS_WITH` function. Postgres only.
353 ///
354 /// # Examples
355 ///
356 /// ```
357 /// use sea_query::{tests_cfg::*, *};
358 ///
359 /// let query = Query::select()
360 /// .expr(PgFunc::starts_with("123", "1"))
361 /// .to_owned();
362 ///
363 /// assert_eq!(
364 /// query.to_string(PostgresQueryBuilder),
365 /// r#"SELECT STARTS_WITH('123', '1')"#
366 /// );
367 /// ```
368 pub fn starts_with<T, P>(text: T, prefix: P) -> FunctionCall
369 where
370 T: Into<Expr>,
371 P: Into<Expr>,
372 {
373 FunctionCall::new(PgFunc::StartsWith).args([text.into(), prefix.into()])
374 }
375
376 /// Call `GEN_RANDOM_UUID` function. Postgres only.
377 ///
378 /// # Examples
379 ///
380 /// ```
381 /// use sea_query::{tests_cfg::*, *};
382 ///
383 /// let query = Query::select().expr(PgFunc::gen_random_uuid()).to_owned();
384 ///
385 /// assert_eq!(
386 /// query.to_string(PostgresQueryBuilder),
387 /// r#"SELECT GEN_RANDOM_UUID()"#
388 /// );
389 /// ```
390 pub fn gen_random_uuid() -> FunctionCall {
391 FunctionCall::new(PgFunc::GenRandomUUID)
392 }
393
394 /// Call the `JSON_BUILD_OBJECT` function. Postgres only.
395 ///
396 /// # Examples
397 ///
398 /// ```
399 /// use sea_query::{tests_cfg::*, *};
400 ///
401 /// let query = Query::select()
402 /// .expr(PgFunc::json_build_object(vec![
403 /// (Expr::val("a"), Expr::val(1)),
404 /// (Expr::val("b"), Expr::val("2")),
405 /// ]))
406 /// .to_owned();
407 ///
408 /// assert_eq!(
409 /// query.to_string(PostgresQueryBuilder),
410 /// r#"SELECT JSON_BUILD_OBJECT('a', 1, 'b', '2')"#
411 /// );
412 /// ```
413 pub fn json_build_object<T>(pairs: Vec<(T, T)>) -> FunctionCall
414 where
415 T: Into<Expr>,
416 {
417 let mut args = vec![];
418 for (key, value) in pairs {
419 args.push(key.into());
420 args.push(value.into());
421 }
422 FunctionCall::new(PgFunc::JsonBuildObject).args(args)
423 }
424
425 /// Call the `DATE_TRUNC` function. Postgres only.
426 ///
427 /// # Examples
428 ///
429 /// ```
430 /// use sea_query::{tests_cfg::*, *};
431 ///
432 /// let query = Query::select()
433 /// .expr(PgFunc::date_trunc(
434 /// PgDateTruncUnit::Day,
435 /// Expr::val("2020-01-01"),
436 /// ))
437 /// .to_owned();
438 ///
439 /// assert_eq!(
440 /// query.to_string(PostgresQueryBuilder),
441 /// r#"SELECT DATE_TRUNC('day', '2020-01-01')"#
442 /// );
443 ///
444 /// let query = Query::select()
445 /// .expr(PgFunc::date_trunc(
446 /// PgDateTruncUnit::Microseconds,
447 /// Expr::val("2020-01-01"),
448 /// ))
449 /// .to_owned();
450 ///
451 /// assert_eq!(
452 /// query.to_string(PostgresQueryBuilder),
453 /// r#"SELECT DATE_TRUNC('microseconds', '2020-01-01')"#
454 /// );
455 /// ```
456 pub fn date_trunc<T>(unit: PgDateTruncUnit, expr: T) -> FunctionCall
457 where
458 T: Into<Expr>,
459 {
460 FunctionCall::new(PgFunc::DateTrunc).args([Expr::val(unit.to_string()), expr.into()])
461 }
462
463 /// Call the `JSON_AGG` function. Postgres only.
464 ///
465 /// # Examples
466 ///
467 /// ```
468 /// use sea_query::{tests_cfg::*, *};
469 ///
470 /// let query = Query::select()
471 /// .from(Char::Table)
472 /// .expr(PgFunc::json_agg(Expr::col(Char::SizeW)))
473 /// .to_owned();
474 ///
475 /// assert_eq!(
476 /// query.to_string(PostgresQueryBuilder),
477 /// r#"SELECT JSON_AGG("size_w") FROM "character""#
478 /// );
479 /// ```
480 pub fn json_agg<T>(expr: T) -> FunctionCall
481 where
482 T: Into<Expr>,
483 {
484 FunctionCall::new(PgFunc::JsonAgg).arg(expr)
485 }
486
487 /// Call the `ARRAY_AGG` function. Postgres only.
488 ///
489 /// # Examples
490 ///
491 /// ```
492 /// use sea_query::{tests_cfg::*, *};
493 ///
494 /// let query = Query::select()
495 /// .from(Char::Table)
496 /// .expr(PgFunc::array_agg(Expr::col(Char::Id)))
497 /// .group_by_col(Char::Character)
498 /// .to_owned();
499 ///
500 /// assert_eq!(
501 /// query.to_string(PostgresQueryBuilder),
502 /// r#"SELECT ARRAY_AGG("id") FROM "character" GROUP BY "character""#
503 /// );
504 /// ```
505 pub fn array_agg<T>(expr: T) -> FunctionCall
506 where
507 T: Into<Expr>,
508 {
509 FunctionCall::new(PgFunc::ArrayAgg).arg(expr)
510 }
511
512 /// Call the `ARRAY_AGG` function with the `DISTINCT` modifier. Postgres only.
513 ///
514 /// # Examples
515 ///
516 /// ```
517 /// use sea_query::{tests_cfg::*, *};
518 ///
519 /// let query = Query::select()
520 /// .from(Char::Table)
521 /// .expr(PgFunc::array_agg_distinct(Expr::col(Char::Id)))
522 /// .group_by_col(Char::Character)
523 /// .to_owned();
524 ///
525 /// assert_eq!(
526 /// query.to_string(PostgresQueryBuilder),
527 /// r#"SELECT ARRAY_AGG(DISTINCT "id") FROM "character" GROUP BY "character""#
528 /// );
529 /// ```
530 pub fn array_agg_distinct<T>(expr: T) -> FunctionCall
531 where
532 T: Into<Expr>,
533 {
534 FunctionCall::new(PgFunc::ArrayAgg).arg_with(expr, FuncArgMod { distinct: true })
535 }
536
537 /// Call `PG_ADVISORY_LOCK` function. Postgres only.
538 ///
539 /// # Examples
540 ///
541 /// ```
542 /// use sea_query::{tests_cfg::*, *};
543 ///
544 /// let query = Query::select()
545 /// .expr(PgFunc::advisory_lock(Expr::val(12345_i64)))
546 /// .to_owned();
547 ///
548 /// assert_eq!(
549 /// query.to_string(PostgresQueryBuilder),
550 /// r#"SELECT PG_ADVISORY_LOCK(12345)"#
551 /// );
552 /// ```
553 pub fn advisory_lock<T>(key: T) -> FunctionCall
554 where
555 T: Into<Expr>,
556 {
557 FunctionCall::new(PgFunc::AdvisoryLock).arg(key)
558 }
559
560 /// Call `PG_ADVISORY_LOCK_SHARED` function. Postgres only.
561 ///
562 /// # Examples
563 ///
564 /// ```
565 /// use sea_query::{tests_cfg::*, *};
566 ///
567 /// let query = Query::select()
568 /// .expr(PgFunc::advisory_lock_shared(Expr::val(12345_i64)))
569 /// .to_owned();
570 ///
571 /// assert_eq!(
572 /// query.to_string(PostgresQueryBuilder),
573 /// r#"SELECT PG_ADVISORY_LOCK_SHARED(12345)"#
574 /// );
575 /// ```
576 pub fn advisory_lock_shared<T>(key: T) -> FunctionCall
577 where
578 T: Into<Expr>,
579 {
580 FunctionCall::new(PgFunc::AdvisoryLockShared).arg(key)
581 }
582
583 /// Call `PG_TRY_ADVISORY_LOCK` function. Postgres only.
584 ///
585 /// # Examples
586 ///
587 /// ```
588 /// use sea_query::{tests_cfg::*, *};
589 ///
590 /// let query = Query::select()
591 /// .expr(PgFunc::try_advisory_lock(Expr::val(12345_i64)))
592 /// .to_owned();
593 ///
594 /// assert_eq!(
595 /// query.to_string(PostgresQueryBuilder),
596 /// r#"SELECT PG_TRY_ADVISORY_LOCK(12345)"#
597 /// );
598 /// ```
599 pub fn try_advisory_lock<T>(key: T) -> FunctionCall
600 where
601 T: Into<Expr>,
602 {
603 FunctionCall::new(PgFunc::TryAdvisoryLock).arg(key)
604 }
605
606 /// Call `PG_TRY_ADVISORY_LOCK_SHARED` function. Postgres only.
607 ///
608 /// # Examples
609 ///
610 /// ```
611 /// use sea_query::{tests_cfg::*, *};
612 ///
613 /// let query = Query::select()
614 /// .expr(PgFunc::try_advisory_lock_shared(Expr::val(12345_i64)))
615 /// .to_owned();
616 ///
617 /// assert_eq!(
618 /// query.to_string(PostgresQueryBuilder),
619 /// r#"SELECT PG_TRY_ADVISORY_LOCK_SHARED(12345)"#
620 /// );
621 /// ```
622 pub fn try_advisory_lock_shared<T>(key: T) -> FunctionCall
623 where
624 T: Into<Expr>,
625 {
626 FunctionCall::new(PgFunc::TryAdvisoryLockShared).arg(key)
627 }
628
629 /// Call `PG_ADVISORY_UNLOCK` function. Postgres only.
630 ///
631 /// # Examples
632 ///
633 /// ```
634 /// use sea_query::{tests_cfg::*, *};
635 ///
636 /// let query = Query::select()
637 /// .expr(PgFunc::advisory_unlock(Expr::val(12345_i64)))
638 /// .to_owned();
639 ///
640 /// assert_eq!(
641 /// query.to_string(PostgresQueryBuilder),
642 /// r#"SELECT PG_ADVISORY_UNLOCK(12345)"#
643 /// );
644 /// ```
645 pub fn advisory_unlock<T>(key: T) -> FunctionCall
646 where
647 T: Into<Expr>,
648 {
649 FunctionCall::new(PgFunc::AdvisoryUnlock).arg(key)
650 }
651
652 /// Call `PG_ADVISORY_UNLOCK_SHARED` function. Postgres only.
653 ///
654 /// # Examples
655 ///
656 /// ```
657 /// use sea_query::{tests_cfg::*, *};
658 ///
659 /// let query = Query::select()
660 /// .expr(PgFunc::advisory_unlock_shared(Expr::val(12345_i64)))
661 /// .to_owned();
662 ///
663 /// assert_eq!(
664 /// query.to_string(PostgresQueryBuilder),
665 /// r#"SELECT PG_ADVISORY_UNLOCK_SHARED(12345)"#
666 /// );
667 /// ```
668 pub fn advisory_unlock_shared<T>(key: T) -> FunctionCall
669 where
670 T: Into<Expr>,
671 {
672 FunctionCall::new(PgFunc::AdvisoryUnlockShared).arg(key)
673 }
674
675 /// Call `PG_ADVISORY_UNLOCK_ALL` function. Postgres only.
676 ///
677 /// # Examples
678 ///
679 /// ```
680 /// use sea_query::{tests_cfg::*, *};
681 ///
682 /// let query = Query::select()
683 /// .expr(PgFunc::advisory_unlock_all())
684 /// .to_owned();
685 ///
686 /// assert_eq!(
687 /// query.to_string(PostgresQueryBuilder),
688 /// r#"SELECT PG_ADVISORY_UNLOCK_ALL()"#
689 /// );
690 /// ```
691 pub fn advisory_unlock_all() -> FunctionCall {
692 FunctionCall::new(PgFunc::AdvisoryUnlockAll)
693 }
694
695 /// Call `PG_ADVISORY_XACT_LOCK` function. Postgres only.
696 ///
697 /// # Examples
698 ///
699 /// ```
700 /// use sea_query::{tests_cfg::*, *};
701 ///
702 /// let query = Query::select()
703 /// .expr(PgFunc::advisory_xact_lock(Expr::val(12345_i64)))
704 /// .to_owned();
705 ///
706 /// assert_eq!(
707 /// query.to_string(PostgresQueryBuilder),
708 /// r#"SELECT PG_ADVISORY_XACT_LOCK(12345)"#
709 /// );
710 /// ```
711 pub fn advisory_xact_lock<T>(key: T) -> FunctionCall
712 where
713 T: Into<Expr>,
714 {
715 FunctionCall::new(PgFunc::AdvisoryXactLock).arg(key)
716 }
717
718 /// Call `PG_ADVISORY_XACT_LOCK_SHARED` function. Postgres only.
719 ///
720 /// # Examples
721 ///
722 /// ```
723 /// use sea_query::{tests_cfg::*, *};
724 ///
725 /// let query = Query::select()
726 /// .expr(PgFunc::advisory_xact_lock_shared(Expr::val(12345_i64)))
727 /// .to_owned();
728 ///
729 /// assert_eq!(
730 /// query.to_string(PostgresQueryBuilder),
731 /// r#"SELECT PG_ADVISORY_XACT_LOCK_SHARED(12345)"#
732 /// );
733 /// ```
734 pub fn advisory_xact_lock_shared<T>(key: T) -> FunctionCall
735 where
736 T: Into<Expr>,
737 {
738 FunctionCall::new(PgFunc::AdvisoryXactLockShared).arg(key)
739 }
740
741 /// Call `PG_TRY_ADVISORY_XACT_LOCK` function. Postgres only.
742 ///
743 /// # Examples
744 ///
745 /// ```
746 /// use sea_query::{tests_cfg::*, *};
747 ///
748 /// let query = Query::select()
749 /// .expr(PgFunc::try_advisory_xact_lock(Expr::val(12345_i64)))
750 /// .to_owned();
751 ///
752 /// assert_eq!(
753 /// query.to_string(PostgresQueryBuilder),
754 /// r#"SELECT PG_TRY_ADVISORY_XACT_LOCK(12345)"#
755 /// );
756 /// ```
757 pub fn try_advisory_xact_lock<T>(key: T) -> FunctionCall
758 where
759 T: Into<Expr>,
760 {
761 FunctionCall::new(PgFunc::TryAdvisoryXactLock).arg(key)
762 }
763
764 /// Call `PG_TRY_ADVISORY_XACT_LOCK_SHARED` function. Postgres only.
765 ///
766 /// # Examples
767 ///
768 /// ```
769 /// use sea_query::{tests_cfg::*, *};
770 ///
771 /// let query = Query::select()
772 /// .expr(PgFunc::try_advisory_xact_lock_shared(Expr::val(12345_i64)))
773 /// .to_owned();
774 ///
775 /// assert_eq!(
776 /// query.to_string(PostgresQueryBuilder),
777 /// r#"SELECT PG_TRY_ADVISORY_XACT_LOCK_SHARED(12345)"#
778 /// );
779 /// ```
780 pub fn try_advisory_xact_lock_shared<T>(key: T) -> FunctionCall
781 where
782 T: Into<Expr>,
783 {
784 FunctionCall::new(PgFunc::TryAdvisoryXactLockShared).arg(key)
785 }
786}