use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_repr::{Deserialize_repr, Serialize_repr};
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum TransactionStmtKind {
Begin,
Start,
Commit,
Rollback,
Savepoint,
Release,
RollbackTo,
Prepare,
CommitPrepared,
RollbackPrepared,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct TransactionStmt {
pub kind: TransactionStmtKind,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct RawStmt {
pub stmt: Stmt,
#[serde(default)]
pub stmt_location: i32,
pub stmt_len: Option<i32>,
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum SetOperation {
None,
Union,
Intersect,
Except,
}
impl Default for SetOperation {
fn default() -> Self {
Self::None
}
}
#[derive(Debug, Deserialize, Serialize)]
pub enum SelectChild {
SelectStmt(SelectStmt),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SelectStmt {
#[serde(rename = "distinctClause")]
pub distinct_clause: Option<Value>,
#[serde(rename = "intoClause")]
pub into_clause: Option<Value>,
#[serde(rename = "targetList")]
pub target_list: Option<Vec<Value>>,
#[serde(rename = "fromClause")]
pub from_clause: Option<Value>,
#[serde(rename = "whereClause")]
pub where_clause: Option<Value>,
#[serde(rename = "groupClause")]
pub group_clause: Option<Value>,
#[serde(rename = "havingClause")]
pub having_clause: Option<Value>,
#[serde(rename = "windowClause")]
pub window_clause: Option<Value>,
#[serde(rename = "valuesLists")]
values_lists: Option<Value>,
#[serde(rename = "sortClause")]
sort_clause: Option<Value>,
#[serde(rename = "limitOffset")]
limit_offset: Option<Value>,
#[serde(rename = "limitCount")]
limit_count: Option<Value>,
#[serde(rename = "lockingClause")]
locking_clause: Option<Value>,
#[serde(rename = "withClause")]
with_clause: Option<Value>,
#[serde(default)]
pub op: SetOperation,
#[serde(default)]
pub all: bool,
pub larg: Option<Box<SelectChild>>,
pub rarg: Option<Box<SelectChild>>,
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum SortByDir {
Default,
Asc,
Desc,
Using,
}
impl Default for SortByDir {
fn default() -> Self {
Self::Default
}
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum SortByNulls {
Default,
First,
Last,
}
impl Default for SortByNulls {
fn default() -> Self {
Self::Default
}
}
#[derive(Debug, Deserialize, Serialize)]
pub struct IndexElem {
name: String,
expr: Option<String>,
indexcolname: Option<String>,
collation: Option<Value>,
#[serde(default)]
opclass: Vec<Value>,
#[serde(default)]
ordering: SortByDir,
#[serde(default)]
nulls_ordering: SortByNulls,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum IndexParams {
IndexElem(IndexElem),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct RangeVar {
pub catalogname: Option<String>,
pub schemaname: Option<String>,
pub relname: String,
pub inh: bool,
pub relpersistence: String,
pub alias: Option<Value>,
pub location: i32,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum RelationKind {
RangeVar(RangeVar),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct IndexStmt {
#[serde(rename = "accessMethod")]
pub access_method: String,
pub idxname: String,
#[serde(rename = "indexParams")]
pub index_params: Vec<IndexParams>,
pub relation: RelationKind,
#[serde(default)]
pub concurrent: bool,
#[serde(default)]
pub unique: bool,
#[serde(default)]
pub primary: bool,
#[serde(default)]
pub isconstraint: bool,
#[serde(default)]
pub deferrable: bool,
#[serde(default)]
pub initdeferred: bool,
#[serde(default)]
pub transformed: bool,
#[serde(default)]
pub if_not_exists: bool,
#[serde(rename = "tableSpace")]
pub table_space: Option<String>,
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum ObjectType {
AccessMethod,
Aggregate,
Amop,
Amproc,
Attribute,
Cast,
Column,
Collation,
Conversion,
Database,
Default,
Defacl,
Domain,
Domconstraint,
EventTrigger,
Extension,
Fdw,
ForeignServer,
ForeignTable,
Function,
Index,
Language,
Largeobject,
Matview,
Opclass,
Operator,
Opfamily,
Policy,
Publication,
PublicationRel,
Role,
Rule,
Schema,
Sequence,
Subscription,
StatisticExt,
TabConstraint,
Table,
Tablespace,
Transform,
Trigger,
TsConfiguration,
TsDictionary,
TsParser,
TsTemplate,
Type,
UserMapping,
View,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum AlterTableCmds {
AlterTableCmd(AlterTableCmd),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct AlterTableStmt {
pub cmds: Vec<AlterTableCmds>,
pub relation: RelationKind,
pub relkind: ObjectType,
#[serde(default)]
pub missing_ok: bool,
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum DropBehavior {
Restrict,
DropCascade,
}
impl Default for DropBehavior {
fn default() -> Self {
Self::Restrict
}
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum AlterTableType {
AddColumn,
AddColumnRecurse,
AddColumnToView,
ColumnDefault,
DropNotNull,
SetNotNull,
SetStatistics,
SetOptions,
ResetOptions,
SetStorage,
DropColumn,
DropColumnRecurse,
AddIndex,
ReAddIndex,
AddConstraint,
AddConstraintRecurse,
ReAddConstraint,
AlterConstraint,
ValidateConstraint,
ValidateConstraintRecurse,
ProcessedConstraint,
AddIndexConstraint,
DropConstraint,
DropConstraintRecurse,
ReAddComment,
AlterColumnType,
AlterColumnGenericOptions,
ChangeOwner,
ClusterOn,
DropCluster,
SetLogged,
SetUnLogged,
AddOids,
AddOidsRecurse,
DropOids,
SetTableSpace,
SetRelOptions,
ResetRelOptions,
ReplaceRelOptions,
EnableTrig,
EnableAlwaysTrig,
EnableReplicaTrig,
DisableTrig,
EnableTrigAll,
DisableTrigAll,
EnableTrigUser,
DisableTrigUser,
EnableRule,
EnableAlwaysRule,
EnableReplicaRule,
DisableRule,
AddInherit,
DropInherit,
AddOf,
DropOf,
ReplicaIdentity,
EnableRowSecurity,
DisableRowSecurity,
ForceRowSecurity,
NoForceRowSecurity,
GenericOptions,
AttachPartition,
DetachPartition,
AddIdentity,
SetIdentity,
DropIdentity,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum ColumnDefConstraint {
Constraint(Constraint),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct PGString {
pub str: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum QualifiedName {
String(PGString),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct TypeName {
#[serde(default)]
pub names: Vec<QualifiedName>,
#[serde(rename = "typeOid")]
pub type_oid: Option<Value>,
#[serde(default)]
pub setof: bool,
#[serde(default)]
pub pct_type: bool,
#[serde(default)]
pub typmods: Vec<Value>,
pub typemod: i32,
#[serde(rename = "arrayBounds", default)]
pub array_bounds: Vec<Value>,
pub location: i32,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum ColumnDefTypeName {
TypeName(TypeName),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ColumnDef {
pub colname: Option<String>,
#[serde(rename = "typeName")]
pub type_name: ColumnDefTypeName,
#[serde(default)]
pub constraints: Vec<ColumnDefConstraint>,
#[serde(default)]
pub is_local: bool,
pub location: i32,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum AlterTableDef {
Constraint(Constraint),
ColumnDef(ColumnDef),
#[serde(rename = "A_Const")]
Constant(Value),
ReplicaIdentityStmt(Value),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct AlterTableCmd {
pub subtype: AlterTableType,
pub name: Option<String>,
pub def: Option<AlterTableDef>,
#[serde(default)]
pub behavior: DropBehavior,
#[serde(default)]
pub missing_ok: bool,
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum ConstrType {
Null,
NotNull,
Default,
Identity,
Check,
Primary,
Unique,
Exclusion,
Foreign,
AttrDeferrable,
AttrNotDeferrable,
AttrDeferred,
AttrImmediate,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Constraint {
pub contype: ConstrType,
pub location: i32,
pub raw_expr: Option<Value>,
pub keys: Option<Value>,
pub indexname: Option<String>,
#[serde(default)]
pub skip_validation: bool,
#[serde(default)]
pub initially_valid: bool,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct RenameStmt {
pub newname: String,
pub behavior: DropBehavior,
pub relation: Option<RelationKind>,
#[serde(rename = "relationType")]
pub relation_type: ObjectType,
#[serde(rename = "renameType")]
pub rename_type: ObjectType,
pub subname: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum TableElt {
ColumnDef(ColumnDef),
}
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum OnCommitAction {
Noop,
PreserveRows,
DeleteRows,
Drop,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct CreateStmt {
pub relation: RelationKind,
#[serde(rename = "tableElts")]
pub table_elts: Vec<TableElt>,
#[serde(rename = "inhRelations")]
#[serde(default)]
pub inh_relations: Vec<Value>,
pub partbound: Option<Value>,
pub partspec: Option<Value>,
#[serde(rename = "ofTypename")]
pub of_typename: Option<Value>,
#[serde(default)]
pub constraints: Vec<Constraint>,
#[serde(default)]
pub options: Vec<Value>,
pub oncommit: OnCommitAction,
pub tablespacename: Option<String>,
#[serde(default)]
pub if_not_exists: bool,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum RootStmt {
RawStmt(RawStmt),
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Deserialize, Serialize)]
pub enum Stmt {
TransactionStmt(TransactionStmt),
SelectStmt(SelectStmt),
IndexStmt(IndexStmt),
AlterTableStmt(AlterTableStmt),
RenameStmt(RenameStmt),
CreateStmt(CreateStmt),
InsertStmt(Value),
UpdateStmt(Value),
DeleteStmt(Value),
CreateSchemaStmt(Value),
AlterDomainStmt(Value),
GrantStmt(Value),
GrantRoleStmt(Value),
AlterDefaultPrivilegesStmt(Value),
CopyStmt(Value),
VariableSetStmt(Value),
VariableShowStmt(Value),
CreateTableSpaceStmt(Value),
DropTableSpaceStmt(Value),
CreateExtensionStmt(Value),
AlterExtensionStmt(Value),
DropStmt(Value),
AlterObjectSchemaStmt(Value),
AlterExtensionContentsStmt(Value),
CreateFdwStmt(Value),
AlterFdwStmt(Value),
CreateForeignServerStmt(Value),
AlterForeignServerStmt(Value),
CreateForeignTableStmt(Value),
CreateUserMappingStmt(Value),
AlterUserMappingStmt(Value),
DropUserMappingStmt(Value),
ImportForeignSchemaStmt(Value),
CreatePolicyStmt(Value),
AlterPolicyStmt(Value),
CreateAmStmt(Value),
CreateTrigStmt(Value),
CreateEventTrigStmt(Value),
AlterEventTrigStmt(Value),
CreateFunctionStmt(Value),
AlterFunctionStmt(Value),
CreatePLangStmt(Value),
CreateRoleStmt(Value),
AlterRoleStmt(Value),
AlterRoleSetStmt(Value),
DropRoleStmt(Value),
CreateSeqStmt(Value),
AlterSeqStmt(Value),
DefineStmt(Value),
CreateDomainStmt(Value),
CreateOpClassStmt(Value),
CreateOpFamilyStmt(Value),
AlterOpFamilyStmt(Value),
TruncateStmt(Value),
CommentStmt(Value),
SecLabelStmt(Value),
DeclareCursorStmt(Value),
ClosePortalStmt(Value),
FetchStmt(Value),
CreateStatsStmt(Value),
ExplainStmt(Value),
AlterOwnerStmt(Value),
DoStmt(Value),
AlterObjectDependsStmt(Value),
AlterOperatorStmt(Value),
RuleStmt(Value),
NotifyStmt(Value),
ListenStmt(Value),
UnlistenStmt(Value),
CompositeTypeStmt(Value),
CreateEnumStmt(Value),
CreateRangeStmt(Value),
AlterEnumStmt(Value),
ViewStmt(Value),
LoadStmt(Value),
CreatedbStmt(Value),
AlterDatabaseStmt(Value),
AlterDatabaseSetStmt(Value),
DropdbStmt(Value),
AlterSystemStmt(Value),
ClusterStmt(Value),
VacuumStmt(Value),
CreateTableAsStmt(Value),
RefreshMatViewStmt(Value),
CheckPointStmt(Value),
DiscardStmt(Value),
LockStmt(Value),
ConstraintsSetStmt(Value),
ReindexStmt(Value),
CreateConversionStmt(Value),
CreateCastStmt(Value),
CreateTransformStmt(Value),
PrepareStmt(Value),
ExecuteStmt(Value),
DeallocateStmt(Value),
DropOwnedStmt(Value),
ReassignOwnedStmt(Value),
AlterTSDictionaryStmt(Value),
AlterTSConfigurationStmt(Value),
CreatePublicationStmt(Value),
AlterPublicationStmt(Value),
CreateSubscriptionStmt(Value),
AlterSubscriptionStmt(Value),
DropSubscriptionStmt(Value),
}