pgx_sql_entity_graph/pg_trigger/
attribute.rs1use crate::ToSqlConfig;
10use proc_macro2::Span;
11use syn::parse::{Parse, ParseStream};
12use syn::Token;
13
14#[derive(Debug, Clone, Hash, Eq, PartialEq)]
15pub enum PgTriggerAttribute {
16 Sql(ToSqlConfig),
17}
18
19impl Parse for PgTriggerAttribute {
20 fn parse(input: ParseStream) -> Result<Self, syn::Error> {
21 let ident: syn::Ident = input.parse()?;
22 let found = match ident.to_string().as_str() {
23 "sql" => {
24 use crate::pgx_attribute::ArgValue;
25 use syn::Lit;
26
27 let _eq: Token![=] = input.parse()?;
28 match input.parse::<ArgValue>()? {
29 ArgValue::Path(p) => Self::Sql(ToSqlConfig::from(p)),
30 ArgValue::Lit(Lit::Bool(b)) => Self::Sql(ToSqlConfig::from(b.value)),
31 ArgValue::Lit(Lit::Str(s)) => Self::Sql(ToSqlConfig::from(s)),
32 ArgValue::Lit(other) => {
33 return Err(syn::Error::new(
34 other.span(),
35 "expected boolean, path, or string literal",
36 ))
37 }
38 }
39 }
40 e => {
41 return Err(syn::Error::new(
42 Span::call_site(),
43 format!(
44 "Invalid option `{}` inside `{} {}`",
45 e,
46 ident.to_string(),
47 input.to_string()
48 ),
49 ))
50 }
51 };
52 Ok(found)
53 }
54}