pub use smol_str::SmolStr as Str;
pub use ordered_float;
pub type Set<T> = hashbrown::HashSet<T>;
pub type Map<T> = hashbrown::HashMap<Str, T>;
mod struct_gen;
pub use struct_gen::*;
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct AclItem<G> {
pub grantee: Option<Str>,
pub grantor: Str,
pub grants: Vec<Grant<G>>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct Grant<G> {
pub privilege: G,
pub with_grant_option: bool,
}
pub type DbAclItem = AclItem<DbAclPrivilege>;
pub type DbGrant = Grant<DbAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum DbAclPrivilege { CREATE, TEMPORARY, CONNECT }
pub type FunctionAclItem = AclItem<FunctionAclPrivilege>;
pub type FunctionGrant = Grant<FunctionAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum FunctionAclPrivilege { EXECUTE }
pub type ForeignDataWrapperAclItem = AclItem<ForeignDataWrapperAclPrivilege>;
pub type ForeignDataWrapperGrant = Grant<ForeignDataWrapperAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum ForeignDataWrapperAclPrivilege { USAGE }
pub type ForeignServerAclItem = AclItem<ForeignServerAclPrivilege>;
pub type ForeignServerGrant = Grant<ForeignServerAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum ForeignServerAclPrivilege { USAGE }
pub type LanguageAclItem = AclItem<LanguageAclPrivilege>;
pub type LanguageGrant = Grant<LanguageAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum LanguageAclPrivilege { USAGE }
pub type ParameterAclItem = AclItem<ParameterAclPrivilege>;
pub type ParameterGrant = Grant<ParameterAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum ParameterAclPrivilege { SET, #[postgres(name = "ALTER SYSTEM")] ALTERSYSTEM }
pub type SchemaAclItem = AclItem<SchemaAclPrivilege>;
pub type SchemaGrant = Grant<SchemaAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum SchemaAclPrivilege { USAGE, CREATE }
pub type TableAclItem = AclItem<TableAclPrivilege>;
pub type TableGrant = Grant<TableAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum TableAclPrivilege { INSERT, SELECT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, MAINTAIN, USAGE }
pub type TableColumnAclItem = AclItem<TableColumnAclPrivilege>;
pub type TableColumnGrant = Grant<TableColumnAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum TableColumnAclPrivilege { INSERT, SELECT, UPDATE, REFERENCES }
pub type TypeAclItem = AclItem<TypeAclPrivilege>;
pub type TypeGrant = Grant<TypeAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum TypeAclPrivilege { USAGE }
pub type AclDefaultAclItem = AclItem<AclDefaultAclPrivilege>;
pub type AclDefaultGrant = Grant<AclDefaultAclPrivilege>;
#[derive(Copy, Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Ord, PartialOrd, postgres_types::FromSql, postgres_types::ToSql)]
pub enum AclDefaultAclPrivilege {
INSERT, SELECT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, MAINTAIN,
USAGE,
EXECUTE,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct DbState {
pub pg_aggregate: Vec<PgAggregate>,
pub pg_am: Set<PgAm>,
pub pg_amop: Vec<PgAmop>,
pub pg_amproc: Vec<PgAmproc>,
pub pg_attrdef: Vec<PgAttrdef>,
pub pg_attribute: Vec<PgAttribute>,
pub pg_roles: Set<PgRoles>,
pub pg_auth_members: Vec<PgAuthMembers>,
pub pg_cast: Vec<PgCast>,
pub pg_class: Set<PgClass>,
pub pg_collation: Vec<PgCollation>,
pub pg_constraint: Vec<PgConstraint>,
pub pg_conversion: Vec<PgConversion>,
pub pg_database: PgDatabase,
pub pg_db_role_setting: Vec<PgDbRoleSetting>,
pub pg_default_acl: Vec<PgDefaultAcl>,
pub pg_enum: Set<PgEnum>,
pub pg_event_trigger: Vec<PgEventTrigger>,
pub pg_extension: Vec<PgExtension>,
pub pg_foreign_data_wrapper: Vec<PgForeignDataWrapper>,
pub pg_foreign_server: Vec<PgForeignServer>,
pub pg_foreign_table: Vec<PgForeignTable>,
pub pg_index: Vec<PgIndex>,
pub pg_inherits: Vec<PgInherits>,
pub pg_language: Set<PgLanguage>,
pub pg_namespace: Set<PgNamespace>,
pub pg_opclass: Vec<PgOpclass>,
pub pg_operator: Set<PgOperator>,
pub pg_opfamily: Vec<PgOpfamily>,
pub pg_parameter_acl: Vec<PgParameterAcl>,
pub pg_partitioned_table: Vec<PgPartitionedTable>,
pub pg_policy: Vec<PgPolicy>,
pub pg_proc: Set<PgProc>,
pub pg_publication: Set<PgPublication>,
pub pg_publication_namespace: Vec<PgPublicationNamespace>,
pub pg_publication_rel: Vec<PgPublicationRel>,
pub pg_range: Vec<PgRange>,
pub pg_rules: Vec<PgRules>,
pub pg_views: Vec<PgViews>,
pub pg_matviews: Vec<PgMatviews>,
pub pg_sequence: Vec<PgSequence>,
pub pg_statistic_ext: Vec<PgStatisticExt>,
pub pg_subscription: Vec<PgSubscription>,
pub pg_transform: Vec<PgTransform>,
pub pg_trigger: Vec<PgTrigger>,
pub pg_ts_config: Set<PgTsConfig>,
pub pg_ts_config_map: Vec<PgTsConfigMap>,
pub pg_ts_dict: Set<PgTsDict>,
pub pg_ts_parser: Vec<PgTsParser>,
pub pg_ts_template: Vec<PgTsTemplate>,
pub pg_type: Set<PgType>,
pub pg_user_mappings: Vec<PgUserMappings>,
}
macro_rules! impl_hash_and_equivalent {
($type:ty, $field:ident) => {
impl std::hash::Hash for $type {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.$field.hash(state);
}
}
impl hashbrown::Equivalent<$type> for str {
fn equivalent(&self, key: &$type) -> bool {
key.$field == *self
}
}
impl hashbrown::Equivalent<$type> for Str {
fn equivalent(&self, key: &$type) -> bool {
key.$field == *self
}
}
};
}
pub(crate) use impl_hash_and_equivalent;
macro_rules! pg_char_enum {
($name:ident { $($char:literal => $variant:ident),* $(,)? }) => {
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone)]
pub enum $name {
$($variant),*
}
impl $name {
pub fn pg_from_char(c: i8) -> $name {
match c as u8 as char {
$($char => $name::$variant,)*
_ => panic!(
"unknown {} variant: {}",
stringify!($name),
c as u8 as char
),
}
}
}
};
}
pub(crate) use pg_char_enum;
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone)]
pub struct PgDbRoleSetting {
pub setdatabase: Option<()>,
pub setrole: Option<Str>,
pub setconfig: Option<Vec<Str>>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone)]
pub struct PgEnum {
pub enumtypid: Str,
pub enumlabels: Vec<Str>,
}
impl_hash_and_equivalent!(PgEnum, enumtypid);
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone)]
pub struct PgProc {
pub oid: Str,
pub proname: Str,
pub pronamespace: Str,
pub proowner: Str,
pub prolang: Str,
pub procost: Option<ordered_float::NotNan<f32>>,
pub prorows: Option<ordered_float::NotNan<f32>>,
pub provariadic: Option<Str>,
pub prosupport: Option<Str>,
pub prokind: PgProcProkind,
pub prosecdef: bool,
pub proleakproof: bool,
pub proisstrict: bool,
pub proretset: bool,
pub provolatile: PgProcProvolatile,
pub proparallel: PgProcProparallel,
pub pronargs: u16,
pub pronargdefaults: u16,
pub prorettype: Str,
pub proargtypes: Vec<Str>,
pub proallargtypes: Option<Vec<Str>>,
pub proargmodes: Option<Vec<PgProcProargmodes>>,
pub proargnames: Option<Vec<Str>>,
pub proargdefaults: Option<Vec<Option<Str>>>,
pub protrftypes: Option<Vec<Str>>,
pub prosrc: Option<Str>,
pub probin: Option<Str>,
pub prosqlbody: Option<Str>,
pub proconfig: Option<Vec<Str>>,
pub proacl: Option<Vec<FunctionAclItem>>,
pub description: Option<Str>,
}
impl_hash_and_equivalent!(PgProc, oid);
pg_char_enum!(PgProcProkind { 'f' => NormalFunction, 'p' => Procedure, 'a' => AggregateFunction, 'w' => WindowFunction });
pg_char_enum!(PgProcProvolatile { 'i' => Immutable, 's' => Stable, 'v' => Volatile });
pg_char_enum!(PgProcProparallel { 's' => SafeWithoutRestriction, 'r' => RestrictedToGroupLeader, 'u' => Unsafe });
pg_char_enum!(PgProcProargmodes { 'i' => In, 'o' => Out, 'b' => Inout, 'v' => Variadic, 't' => Table });