@@ -270,6 +270,28 @@ pub enum TableConstraint {
270270 /// Referred column identifier list.
271271 columns : Vec < Ident > ,
272272 } ,
273+ /// MySQLs [fulltext][1] definition. Since the [`SPATIAL`][2] definition is exactly the same,
274+ /// and MySQL displays both the same way, it is part of this definition as well.
275+ ///
276+ /// Supported syntax:
277+ ///
278+ /// ```markdown
279+ /// {FULLTEXT | SPATIAL} [INDEX | KEY] [index_name] (key_part,...)
280+ ///
281+ /// key_part: col_name
282+ /// ```
283+ ///
284+ /// [1]: https://dev.mysql.com/doc/refman/8.0/en/fulltext-natural-language.html
285+ FulltextOrSpatial {
286+ /// Whether this is a `FULLTEXT` (true) or `SPATIAL` (false) definition.
287+ fulltext : bool ,
288+ /// Whether the type is followed by the keyword `KEY`, `INDEX`, or no keyword at all.
289+ index_type_display : KeyOrIndexDisplay ,
290+ /// Optional index name.
291+ opt_index_name : Option < Ident > ,
292+ /// Referred column identifier list.
293+ columns : Vec < Ident > ,
294+ } ,
273295}
274296
275297impl fmt:: Display for TableConstraint {
@@ -330,6 +352,64 @@ impl fmt::Display for TableConstraint {
330352
331353 Ok ( ( ) )
332354 }
355+ Self :: FulltextOrSpatial {
356+ fulltext,
357+ index_type_display,
358+ opt_index_name,
359+ columns,
360+ } => {
361+ if * fulltext {
362+ write ! ( f, "FULLTEXT" ) ?;
363+ } else {
364+ write ! ( f, "SPATIAL" ) ?;
365+ }
366+
367+ if !matches ! ( index_type_display, KeyOrIndexDisplay :: None ) {
368+ write ! ( f, " {}" , index_type_display) ?;
369+ }
370+
371+ if let Some ( name) = opt_index_name {
372+ write ! ( f, " {}" , name) ?;
373+ }
374+
375+ write ! ( f, " ({})" , display_comma_separated( columns) ) ?;
376+
377+ Ok ( ( ) )
378+ }
379+ }
380+ }
381+ }
382+
383+ /// Representation whether a definition can can contains the KEY or INDEX keywords with the same
384+ /// meaning.
385+ ///
386+ /// This enum initially is directed to `FULLTEXT`,`SPATIAL`, and `UNIQUE` indexes on create table
387+ /// statements of `MySQL` [(1)].
388+ ///
389+ /// [1]: https://dev.mysql.com/doc/refman/8.0/en/create-table.html
390+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
391+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
392+ pub enum KeyOrIndexDisplay {
393+ /// Nothing to display
394+ None ,
395+ /// Display the KEY keyword
396+ Key ,
397+ /// Display the INDEX keyword
398+ Index ,
399+ }
400+
401+ impl fmt:: Display for KeyOrIndexDisplay {
402+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
403+ match self {
404+ KeyOrIndexDisplay :: None => {
405+ write ! ( f, "" )
406+ }
407+ KeyOrIndexDisplay :: Key => {
408+ write ! ( f, "KEY" )
409+ }
410+ KeyOrIndexDisplay :: Index => {
411+ write ! ( f, "INDEX" )
412+ }
333413 }
334414 }
335415}
0 commit comments