Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5121,6 +5121,151 @@ impl Spanned for AlterOperatorClass {
}
}

/// PostgreSQL text search object kind.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum TextSearchObjectType {
/// `DICTIONARY`
Dictionary,
/// `CONFIGURATION`
Configuration,
/// `TEMPLATE`
Template,
/// `PARSER`
Parser,
}

impl fmt::Display for TextSearchObjectType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
TextSearchObjectType::Dictionary => write!(f, "DICTIONARY"),
TextSearchObjectType::Configuration => write!(f, "CONFIGURATION"),
TextSearchObjectType::Template => write!(f, "TEMPLATE"),
TextSearchObjectType::Parser => write!(f, "PARSER"),
}
}
}

/// PostgreSQL `CREATE TEXT SEARCH ...` statement.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct CreateTextSearch {
/// The specific text search object type.
pub object_type: TextSearchObjectType,
/// Object name.
pub name: ObjectName,
/// Parenthesized options.
pub options: Vec<SqlOption>,
}

impl fmt::Display for CreateTextSearch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"CREATE TEXT SEARCH {} {} ({})",
self.object_type,
self.name,
display_comma_separated(&self.options)
)
}
}

impl Spanned for CreateTextSearch {
fn span(&self) -> Span {
Span::empty()
}
}

/// Option assignment used by `ALTER TEXT SEARCH DICTIONARY ... ( ... )`.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct AlterTextSearchDictionaryOption {
/// Option name.
pub key: Ident,
/// Optional value (`option [= value]`).
pub value: Option<Expr>,
}

impl fmt::Display for AlterTextSearchDictionaryOption {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.value {
Some(value) => write!(f, "{} = {}", self.key, value),
None => write!(f, "{}", self.key),
}
}
}

/// Operation for PostgreSQL `ALTER TEXT SEARCH ...`.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum AlterTextSearchOperation {
/// `RENAME TO new_name`
RenameTo {
/// New name.
new_name: Ident,
},
/// `OWNER TO ...`
OwnerTo(Owner),
/// `SET SCHEMA schema_name`
SetSchema {
/// Target schema.
schema_name: ObjectName,
},
/// `( option [= value] [, ...] )`
SetOptions {
/// Dictionary options to apply.
options: Vec<AlterTextSearchDictionaryOption>,
},
}

impl fmt::Display for AlterTextSearchOperation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AlterTextSearchOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"),
AlterTextSearchOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
AlterTextSearchOperation::SetSchema { schema_name } => {
write!(f, "SET SCHEMA {schema_name}")
}
AlterTextSearchOperation::SetOptions { options } => {
write!(f, "({})", display_comma_separated(options))
}
}
}
}

/// PostgreSQL `ALTER TEXT SEARCH ...` statement.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct AlterTextSearch {
/// The specific text search object type.
pub object_type: TextSearchObjectType,
/// Object name.
pub name: ObjectName,
/// Operation to apply.
pub operation: AlterTextSearchOperation,
}

impl fmt::Display for AlterTextSearch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"ALTER TEXT SEARCH {} {} {}",
self.object_type, self.name, self.operation
)
}
}

impl Spanned for AlterTextSearch {
fn span(&self) -> Span {
Span::empty()
}
}

/// CREATE POLICY statement.
///
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createpolicy.html)
Expand Down
46 changes: 36 additions & 10 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,22 @@ pub use self::ddl::{
AlterOperatorClass, AlterOperatorClassOperation, AlterOperatorFamily,
AlterOperatorFamilyOperation, AlterOperatorOperation, AlterPolicy, AlterPolicyOperation,
AlterSchema, AlterSchemaOperation, AlterTable, AlterTableAlgorithm, AlterTableLock,
AlterTableOperation, AlterTableType, AlterType, AlterTypeAddValue, AlterTypeAddValuePosition,
AlterTableOperation, AlterTableType, AlterTextSearch, AlterTextSearchDictionaryOption,
AlterTextSearchOperation, AlterType, AlterTypeAddValue, AlterTypeAddValuePosition,
AlterTypeOperation, AlterTypeRename, AlterTypeRenameValue, ClusteredBy, ColumnDef,
ColumnOption, ColumnOptionDef, ColumnOptions, ColumnPolicy, ColumnPolicyProperty,
ConstraintCharacteristics, CreateConnector, CreateDomain, CreateExtension, CreateFunction,
CreateIndex, CreateOperator, CreateOperatorClass, CreateOperatorFamily, CreatePolicy,
CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTrigger, CreateView, Deduplicate,
DeferrableInitial, DropBehavior, DropExtension, DropFunction, DropOperator, DropOperatorClass,
DropOperatorFamily, DropOperatorSignature, DropPolicy, DropTrigger, ForValues, GeneratedAs,
GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
IdentityPropertyKind, IdentityPropertyOrder, IndexColumn, IndexOption, IndexType,
KeyOrIndexDisplay, Msck, NullsDistinctOption, OperatorArgTypes, OperatorClassItem,
OperatorFamilyDropItem, OperatorFamilyItem, OperatorOption, OperatorPurpose, Owner, Partition,
PartitionBoundValue, ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity,
TagsColumnOption, TriggerObjectKind, Truncate, UserDefinedTypeCompositeAttributeDef,
CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTextSearch, CreateTrigger,
CreateView, Deduplicate, DeferrableInitial, DropBehavior, DropExtension, DropFunction,
DropOperator, DropOperatorClass, DropOperatorFamily, DropOperatorSignature, DropPolicy,
DropTrigger, ForValues, GeneratedAs, GeneratedExpressionMode, IdentityParameters,
IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder,
IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, Msck, NullsDistinctOption,
OperatorArgTypes, OperatorClassItem, OperatorFamilyDropItem, OperatorFamilyItem,
OperatorOption, OperatorPurpose, Owner, Partition, PartitionBoundValue, ProcedureParam,
ReferentialAction, RenameTableNameKind, ReplicaIdentity, TagsColumnOption,
TextSearchObjectType, TriggerObjectKind, Truncate, UserDefinedTypeCompositeAttributeDef,
UserDefinedTypeInternalLength, UserDefinedTypeRangeOption, UserDefinedTypeRepresentation,
UserDefinedTypeSqlDefinitionOption, UserDefinedTypeStorage, ViewColumnDef,
};
Expand Down Expand Up @@ -3707,6 +3709,11 @@ pub enum Statement {
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createopclass.html)
CreateOperatorClass(CreateOperatorClass),
/// ```sql
/// CREATE TEXT SEARCH { DICTIONARY | CONFIGURATION | TEMPLATE | PARSER }
/// ```
/// See [PostgreSQL](https://www.postgresql.org/docs/current/textsearch-intro.html)
CreateTextSearch(CreateTextSearch),
/// ```sql
/// ALTER TABLE
/// ```
AlterTable(AlterTable),
Expand Down Expand Up @@ -3759,6 +3766,11 @@ pub enum Statement {
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-alteropclass.html)
AlterOperatorClass(AlterOperatorClass),
/// ```sql
/// ALTER TEXT SEARCH { DICTIONARY | CONFIGURATION | TEMPLATE | PARSER }
/// ```
/// See [PostgreSQL](https://www.postgresql.org/docs/current/textsearch-configuration.html)
AlterTextSearch(AlterTextSearch),
/// ```sql
/// ALTER ROLE
/// ```
AlterRole {
Expand Down Expand Up @@ -5443,6 +5455,7 @@ impl fmt::Display for Statement {
create_operator_family.fmt(f)
}
Statement::CreateOperatorClass(create_operator_class) => create_operator_class.fmt(f),
Statement::CreateTextSearch(create_text_search) => create_text_search.fmt(f),
Statement::AlterTable(alter_table) => write!(f, "{alter_table}"),
Statement::AlterIndex { name, operation } => {
write!(f, "ALTER INDEX {name} {operation}")
Expand Down Expand Up @@ -5472,6 +5485,7 @@ impl fmt::Display for Statement {
Statement::AlterOperatorClass(alter_operator_class) => {
write!(f, "{alter_operator_class}")
}
Statement::AlterTextSearch(alter_text_search) => write!(f, "{alter_text_search}"),
Statement::AlterRole { name, operation } => {
write!(f, "ALTER ROLE {name} {operation}")
}
Expand Down Expand Up @@ -11912,6 +11926,12 @@ impl From<CreateOperatorClass> for Statement {
}
}

impl From<CreateTextSearch> for Statement {
fn from(c: CreateTextSearch) -> Self {
Self::CreateTextSearch(c)
}
}

impl From<AlterSchema> for Statement {
fn from(a: AlterSchema) -> Self {
Self::AlterSchema(a)
Expand Down Expand Up @@ -11942,6 +11962,12 @@ impl From<AlterOperatorClass> for Statement {
}
}

impl From<AlterTextSearch> for Statement {
fn from(a: AlterTextSearch) -> Self {
Self::AlterTextSearch(a)
}
}

impl From<Merge> for Statement {
fn from(m: Merge) -> Self {
Self::Merge(m)
Expand Down
2 changes: 2 additions & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl Spanned for Statement {
create_operator_family.span()
}
Statement::CreateOperatorClass(create_operator_class) => create_operator_class.span(),
Statement::CreateTextSearch(create_text_search) => create_text_search.span(),
Statement::AlterTable(alter_table) => alter_table.span(),
Statement::AlterIndex { name, operation } => name.span().union(&operation.span()),
Statement::AlterView {
Expand All @@ -406,6 +407,7 @@ impl Spanned for Statement {
Statement::AlterOperator { .. } => Span::empty(),
Statement::AlterOperatorFamily { .. } => Span::empty(),
Statement::AlterOperatorClass { .. } => Span::empty(),
Statement::AlterTextSearch { .. } => Span::empty(),
Statement::AlterRole { .. } => Span::empty(),
Statement::AlterSession { .. } => Span::empty(),
Statement::AttachDatabase { .. } => Span::empty(),
Expand Down
4 changes: 4 additions & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ define_keywords!(
COMPUTE,
CONCURRENTLY,
CONDITION,
CONFIGURATION,
CONFLICT,
CONNECT,
CONNECTION,
Expand Down Expand Up @@ -328,6 +329,7 @@ define_keywords!(
DETACH,
DETAIL,
DETERMINISTIC,
DICTIONARY,
DIMENSIONS,
DIRECTORY,
DISABLE,
Expand Down Expand Up @@ -756,6 +758,7 @@ define_keywords!(
PARALLEL,
PARAMETER,
PARQUET,
PARSER,
PART,
PARTIAL,
PARTITION,
Expand Down Expand Up @@ -1023,6 +1026,7 @@ define_keywords!(
TASK,
TBLPROPERTIES,
TEMP,
TEMPLATE,
TEMPORARY,
TEMPTABLE,
TERMINATED,
Expand Down
Loading
Loading