pgx_sql_entity_graph/aggregate/options.rs
1/*
2Portions Copyright 2019-2021 ZomboDB, LLC.
3Portions Copyright 2021-2022 Technology Concepts & Design, Inc. <support@tcdi.com>
4
5All rights reserved.
6
7Use of this source code is governed by the MIT license that can be found in the LICENSE file.
8*/
9/*!
10
11`#[pg_aggregate]` related options for Rust to SQL translation
12
13> Like all of the [`sql_entity_graph`][crate::pgx_sql_entity_graph] APIs, this is considered **internal**
14to the `pgx` framework and very subject to change between versions. While you may use this, please do it with caution.
15
16*/
17use crate::{PgxSql, ToSql};
18
19/// Corresponds to the `PARALLEL` and `MFINALFUNC_MODIFY` in [`CREATE AGGREGATE`](https://www.postgresql.org/docs/current/sql-createaggregate.html).
20#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
21pub enum ParallelOption {
22 Safe,
23 Restricted,
24 Unsafe,
25}
26
27impl ToSql for ParallelOption {
28 fn to_sql(&self, _context: &PgxSql) -> eyre::Result<String> {
29 let value = match self {
30 ParallelOption::Safe => String::from("SAFE"),
31 ParallelOption::Restricted => String::from("RESTRICTED"),
32 ParallelOption::Unsafe => String::from("UNSAFE"),
33 };
34 Ok(value)
35 }
36}
37
38/// Corresponds to the `FINALFUNC_MODIFY` and `MFINALFUNC_MODIFY` in [`CREATE AGGREGATE`](https://www.postgresql.org/docs/current/sql-createaggregate.html).
39#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
40pub enum FinalizeModify {
41 ReadOnly,
42 Shareable,
43 ReadWrite,
44}
45
46impl ToSql for FinalizeModify {
47 fn to_sql(&self, _context: &PgxSql) -> eyre::Result<String> {
48 let value = match self {
49 FinalizeModify::ReadOnly => String::from("READ_ONLY"),
50 FinalizeModify::Shareable => String::from("SHAREABLE"),
51 FinalizeModify::ReadWrite => String::from("READ_WRITE"),
52 };
53 Ok(value)
54 }
55}