-
Notifications
You must be signed in to change notification settings - Fork 710
Add PostgreSQL CREATE/ALTER TEXT SEARCH DDL Parsing
#2250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e7b0545
c5adf35
143e0ef
182faf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5430,6 +5430,151 @@ impl Spanned for AlterFunction { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// 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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
same comment regarding doc link |
||||||
| #[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 ... ( ... )`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a link to the docs for this struct? |
||||||
| #[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 ...`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
same comment regarding doc link |
||||||
| #[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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
same comment regarding doc link |
||||||
| #[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) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,23 +65,24 @@ 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, DistStyle, DropBehavior, DropExtension, DropFunction, DropOperator, | ||||||
| DropOperatorClass, DropOperatorFamily, DropOperatorSignature, DropPolicy, DropTrigger, | ||||||
| ForValues, FunctionReturnType, 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, UserDefinedTypeInternalLength, | ||||||
| UserDefinedTypeRangeOption, UserDefinedTypeRepresentation, UserDefinedTypeSqlDefinitionOption, | ||||||
| UserDefinedTypeStorage, ViewColumnDef, | ||||||
| CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTextSearch, CreateTrigger, | ||||||
| CreateView, Deduplicate, DeferrableInitial, DistStyle, DropBehavior, DropExtension, | ||||||
| DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily, DropOperatorSignature, | ||||||
| DropPolicy, DropTrigger, ForValues, FunctionReturnType, 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, | ||||||
| }; | ||||||
| pub use self::dml::{ | ||||||
| Delete, Insert, Merge, MergeAction, MergeClause, MergeClauseKind, MergeInsertExpr, | ||||||
|
|
@@ -3720,6 +3721,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 } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /// ``` | ||||||
| /// See [PostgreSQL](https://www.postgresql.org/docs/current/textsearch-intro.html) | ||||||
| CreateTextSearch(CreateTextSearch), | ||||||
| /// ```sql | ||||||
| /// ALTER TABLE | ||||||
| /// ``` | ||||||
| AlterTable(AlterTable), | ||||||
|
|
@@ -3779,6 +3785,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 } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /// ``` | ||||||
| /// See [PostgreSQL](https://www.postgresql.org/docs/current/textsearch-configuration.html) | ||||||
| AlterTextSearch(AlterTextSearch), | ||||||
| /// ```sql | ||||||
| /// ALTER ROLE | ||||||
| /// ``` | ||||||
| AlterRole { | ||||||
|
|
@@ -5484,6 +5495,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}") | ||||||
|
|
@@ -5514,6 +5526,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}") | ||||||
| } | ||||||
|
|
@@ -12107,6 +12120,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) | ||||||
|
|
@@ -12143,6 +12162,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) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead add a [PostgreSQL] link to the reference docs. We can avoid mentioning a specific dialect as part of the main description (it goes stale quickly/immediately if there are other dialects that support the feature)