1- import { AllDataTypeNodes , NamedDataType } from "sql-parser-cst" ;
1+ import { AllDataTypeNodes , DataType } from "sql-parser-cst" ;
22import { isArray } from "../utils" ;
33import { CstToDocMap } from "../CstToDocMap" ;
4- import { group , indent , softline } from "../print_utils" ;
4+ import { group , indent , join , softline } from "../print_utils" ;
5+ import { isDataTypeName } from "../node_utils" ;
56
67export const dataTypeMap : CstToDocMap < AllDataTypeNodes > = {
8+ data_type_name : ( print ) => print . spaced ( "name" ) ,
79 // print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
8- named_data_type : ( print , node ) =>
9- ( isMultiWordTypeName ( node ) ? print . spaced : print ) ( [ "name" , "params" ] ) ,
10- data_type_identifier : ( print ) => print . spaced ( "name" ) ,
10+ modified_data_type : ( print , node ) =>
11+ ( isMultiWordTypeName ( node . dataType ) ? print . spaced : print ) ( [
12+ "dataType" ,
13+ "modifiers" ,
14+ ] ) ,
15+
1116 setof_data_type : ( print ) => print . spaced ( [ "setofKw" , "dataType" ] ) ,
1217 array_data_type : ( print ) => print ( [ "dataType" , "bounds" ] ) ,
1318 array_bounds : ( print ) => [ "[" , print ( "bounds" ) , "]" ] ,
14- with_time_zone_data_type : ( print ) =>
15- print . spaced ( [ "dataType" , "withTimeZoneKw" ] ) ,
19+ time_data_type : ( print , node ) =>
20+ group (
21+ join ( " " , [
22+ print ( [ "timeKw" , "precision" ] ) ,
23+ ...( node . timeZoneKw ? [ print . spaced ( "timeZoneKw" ) ] : [ ] ) ,
24+ ] ) ,
25+ ) ,
26+ interval_data_type : ( print ) =>
27+ print . spaced ( [ "intervalKw" , "fieldsKw" , "precision" ] ) ,
28+ parametric_data_type : ( print ) => print ( [ "typeKw" , "params" ] ) ,
1629 generic_type_params : ( print ) =>
1730 group ( [ "<" , indent ( [ softline , print ( "params" ) ] ) , softline , ">" ] ) ,
1831 array_type_param : ( print ) => print . spaced ( [ "dataType" , "constraints" ] ) ,
@@ -21,9 +34,6 @@ export const dataTypeMap: CstToDocMap<AllDataTypeNodes> = {
2134 table_data_type : ( print ) => print . spaced ( [ "tableKw" , "columns" ] ) ,
2235} ;
2336
24- function isMultiWordTypeName ( node : NamedDataType ) : boolean {
25- return (
26- isArray ( node . name ) ||
27- ( node . name . type === "data_type_identifier" && isArray ( node . name . name ) )
28- ) ;
37+ function isMultiWordTypeName ( node : DataType ) : boolean {
38+ return isDataTypeName ( node ) && isArray ( node . name ) && node . name . length > 1 ;
2939}
0 commit comments