Skip to content

Commit 089a07b

Browse files
committed
feat(ast): add CREATE TEXT SEARCH CONFIGURATION/DICTIONARY/PARSER/TEMPLATE types
1 parent 19a7468 commit 089a07b

4 files changed

Lines changed: 166 additions & 1 deletion

File tree

src/ast/ddl.rs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5757,3 +5757,127 @@ impl From<AlterPolicy> for crate::ast::Statement {
57575757
crate::ast::Statement::AlterPolicy(v)
57585758
}
57595759
}
5760+
5761+
/// `CREATE TEXT SEARCH CONFIGURATION` statement.
5762+
///
5763+
/// Note: this is a PostgreSQL-specific statement.
5764+
/// <https://www.postgresql.org/docs/current/sql-createtsconfig.html>
5765+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5766+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5767+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5768+
pub struct CreateTextSearchConfiguration {
5769+
/// Name of the text search configuration being created.
5770+
pub name: ObjectName,
5771+
/// Options list — must include `PARSER = parser_name`.
5772+
pub options: Vec<SqlOption>,
5773+
}
5774+
5775+
impl fmt::Display for CreateTextSearchConfiguration {
5776+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5777+
write!(
5778+
f,
5779+
"CREATE TEXT SEARCH CONFIGURATION {name} ({options})",
5780+
name = self.name,
5781+
options = display_comma_separated(&self.options),
5782+
)
5783+
}
5784+
}
5785+
5786+
impl From<CreateTextSearchConfiguration> for crate::ast::Statement {
5787+
fn from(v: CreateTextSearchConfiguration) -> Self {
5788+
crate::ast::Statement::CreateTextSearchConfiguration(v)
5789+
}
5790+
}
5791+
5792+
/// `CREATE TEXT SEARCH DICTIONARY` statement.
5793+
///
5794+
/// Note: this is a PostgreSQL-specific statement.
5795+
/// <https://www.postgresql.org/docs/current/sql-createtsdictionary.html>
5796+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5797+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5798+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5799+
pub struct CreateTextSearchDictionary {
5800+
/// Name of the text search dictionary being created.
5801+
pub name: ObjectName,
5802+
/// Options list — must include `TEMPLATE = template_name`.
5803+
pub options: Vec<SqlOption>,
5804+
}
5805+
5806+
impl fmt::Display for CreateTextSearchDictionary {
5807+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5808+
write!(
5809+
f,
5810+
"CREATE TEXT SEARCH DICTIONARY {name} ({options})",
5811+
name = self.name,
5812+
options = display_comma_separated(&self.options),
5813+
)
5814+
}
5815+
}
5816+
5817+
impl From<CreateTextSearchDictionary> for crate::ast::Statement {
5818+
fn from(v: CreateTextSearchDictionary) -> Self {
5819+
crate::ast::Statement::CreateTextSearchDictionary(v)
5820+
}
5821+
}
5822+
5823+
/// `CREATE TEXT SEARCH PARSER` statement.
5824+
///
5825+
/// Note: this is a PostgreSQL-specific statement.
5826+
/// <https://www.postgresql.org/docs/current/sql-createtsparser.html>
5827+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5828+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5829+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5830+
pub struct CreateTextSearchParser {
5831+
/// Name of the text search parser being created.
5832+
pub name: ObjectName,
5833+
/// Options list — must include `START`, `GETTOKEN`, `END`, `LEXTYPES` (and optionally `HEADLINE`).
5834+
pub options: Vec<SqlOption>,
5835+
}
5836+
5837+
impl fmt::Display for CreateTextSearchParser {
5838+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5839+
write!(
5840+
f,
5841+
"CREATE TEXT SEARCH PARSER {name} ({options})",
5842+
name = self.name,
5843+
options = display_comma_separated(&self.options),
5844+
)
5845+
}
5846+
}
5847+
5848+
impl From<CreateTextSearchParser> for crate::ast::Statement {
5849+
fn from(v: CreateTextSearchParser) -> Self {
5850+
crate::ast::Statement::CreateTextSearchParser(v)
5851+
}
5852+
}
5853+
5854+
/// `CREATE TEXT SEARCH TEMPLATE` statement.
5855+
///
5856+
/// Note: this is a PostgreSQL-specific statement.
5857+
/// <https://www.postgresql.org/docs/current/sql-createtstemplate.html>
5858+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5859+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5860+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5861+
pub struct CreateTextSearchTemplate {
5862+
/// Name of the text search template being created.
5863+
pub name: ObjectName,
5864+
/// Options list — must include `LEXIZE` (and optionally `INIT`).
5865+
pub options: Vec<SqlOption>,
5866+
}
5867+
5868+
impl fmt::Display for CreateTextSearchTemplate {
5869+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5870+
write!(
5871+
f,
5872+
"CREATE TEXT SEARCH TEMPLATE {name} ({options})",
5873+
name = self.name,
5874+
options = display_comma_separated(&self.options),
5875+
)
5876+
}
5877+
}
5878+
5879+
impl From<CreateTextSearchTemplate> for crate::ast::Statement {
5880+
fn from(v: CreateTextSearchTemplate) -> Self {
5881+
crate::ast::Statement::CreateTextSearchTemplate(v)
5882+
}
5883+
}

src/ast/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ pub use self::ddl::{
7171
ColumnPolicyProperty, ConstraintCharacteristics, CreateCollation, CreateCollationDefinition,
7272
CreateConnector, CreateDomain, CreateExtension, CreateFunction, CreateIndex, CreateOperator,
7373
CreateOperatorClass, CreateOperatorFamily, CreatePolicy, CreatePolicyCommand, CreatePolicyType,
74-
CreateTable, CreateTrigger, CreateView, Deduplicate, DeferrableInitial, DistStyle,
74+
CreateTable, CreateTextSearchConfiguration, CreateTextSearchDictionary, CreateTextSearchParser,
75+
CreateTextSearchTemplate, CreateTrigger, CreateView, Deduplicate, DeferrableInitial, DistStyle,
7576
DropBehavior, DropExtension, DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily,
7677
DropOperatorSignature, DropPolicy, DropTrigger, ForValues, FunctionReturnType, GeneratedAs,
7778
GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
@@ -4013,6 +4014,30 @@ pub enum Statement {
40134014
/// <https://www.postgresql.org/docs/current/sql-createcollation.html>
40144015
CreateCollation(CreateCollation),
40154016
/// ```sql
4017+
/// CREATE TEXT SEARCH CONFIGURATION name ( PARSER = parser_name )
4018+
/// ```
4019+
/// Note: this is a PostgreSQL-specific statement.
4020+
/// <https://www.postgresql.org/docs/current/sql-createtsconfig.html>
4021+
CreateTextSearchConfiguration(CreateTextSearchConfiguration),
4022+
/// ```sql
4023+
/// CREATE TEXT SEARCH DICTIONARY name ( TEMPLATE = template_name [, option = value, ...] )
4024+
/// ```
4025+
/// Note: this is a PostgreSQL-specific statement.
4026+
/// <https://www.postgresql.org/docs/current/sql-createtsdictionary.html>
4027+
CreateTextSearchDictionary(CreateTextSearchDictionary),
4028+
/// ```sql
4029+
/// CREATE TEXT SEARCH PARSER name ( START = start_fn, GETTOKEN = gettoken_fn, END = end_fn, LEXTYPES = lextypes_fn [, HEADLINE = headline_fn] )
4030+
/// ```
4031+
/// Note: this is a PostgreSQL-specific statement.
4032+
/// <https://www.postgresql.org/docs/current/sql-createtsparser.html>
4033+
CreateTextSearchParser(CreateTextSearchParser),
4034+
/// ```sql
4035+
/// CREATE TEXT SEARCH TEMPLATE name ( [INIT = init_fn,] LEXIZE = lexize_fn )
4036+
/// ```
4037+
/// Note: this is a PostgreSQL-specific statement.
4038+
/// <https://www.postgresql.org/docs/current/sql-createtstemplate.html>
4039+
CreateTextSearchTemplate(CreateTextSearchTemplate),
4040+
/// ```sql
40164041
/// DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
40174042
/// ```
40184043
/// Note: this is a PostgreSQL-specific statement.
@@ -5495,6 +5520,10 @@ impl fmt::Display for Statement {
54955520
Statement::CreateIndex(create_index) => create_index.fmt(f),
54965521
Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
54975522
Statement::CreateCollation(create_collation) => write!(f, "{create_collation}"),
5523+
Statement::CreateTextSearchConfiguration(v) => write!(f, "{v}"),
5524+
Statement::CreateTextSearchDictionary(v) => write!(f, "{v}"),
5525+
Statement::CreateTextSearchParser(v) => write!(f, "{v}"),
5526+
Statement::CreateTextSearchTemplate(v) => write!(f, "{v}"),
54985527
Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
54995528
Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
55005529
Statement::DropOperatorFamily(drop_operator_family) => {

src/ast/spans.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ impl Spanned for Values {
272272
/// - [Statement::Declare]
273273
/// - [Statement::CreateExtension]
274274
/// - [Statement::CreateCollation]
275+
/// - [Statement::CreateTextSearchConfiguration]
276+
/// - [Statement::CreateTextSearchDictionary]
277+
/// - [Statement::CreateTextSearchParser]
278+
/// - [Statement::CreateTextSearchTemplate]
275279
/// - [Statement::AlterCollation]
276280
/// - [Statement::Fetch]
277281
/// - [Statement::Flush]
@@ -387,6 +391,10 @@ impl Spanned for Statement {
387391
Statement::CreateRole(create_role) => create_role.span(),
388392
Statement::CreateExtension(create_extension) => create_extension.span(),
389393
Statement::CreateCollation(create_collation) => create_collation.span(),
394+
Statement::CreateTextSearchConfiguration(_) => Span::empty(),
395+
Statement::CreateTextSearchDictionary(_) => Span::empty(),
396+
Statement::CreateTextSearchParser(_) => Span::empty(),
397+
Statement::CreateTextSearchTemplate(_) => Span::empty(),
390398
Statement::DropExtension(drop_extension) => drop_extension.span(),
391399
Statement::DropOperator(drop_operator) => drop_operator.span(),
392400
Statement::DropOperatorFamily(drop_operator_family) => drop_operator_family.span(),

src/keywords.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ define_keywords!(
244244
COMPRESSION,
245245
COMPUPDATE,
246246
COMPUTE,
247+
CONFIGURATION,
247248
CONCURRENTLY,
248249
CONDITION,
249250
CONFLICT,
@@ -333,6 +334,7 @@ define_keywords!(
333334
DETACH,
334335
DETAIL,
335336
DETERMINISTIC,
337+
DICTIONARY,
336338
DIMENSIONS,
337339
DIRECTORY,
338340
DISABLE,
@@ -765,6 +767,7 @@ define_keywords!(
765767
PARALLEL,
766768
PARAMETER,
767769
PARQUET,
770+
PARSER,
768771
PART,
769772
PARTIAL,
770773
PARTITION,
@@ -1035,6 +1038,7 @@ define_keywords!(
10351038
TASK,
10361039
TBLPROPERTIES,
10371040
TEMP,
1041+
TEMPLATE,
10381042
TEMPORARY,
10391043
TEMPTABLE,
10401044
TERMINATED,

0 commit comments

Comments
 (0)