@@ -29,13 +29,7 @@ use serde::{Deserialize, Serialize};
2929use sqlparser_derive:: { Visit , VisitMut } ;
3030
3131use crate :: ast:: value:: escape_single_quote_string;
32- use crate :: ast:: {
33- display_comma_separated, display_separated, CommentDef , CreateFunctionBody ,
34- CreateFunctionUsing , DataType , Expr , FunctionBehavior , FunctionCalledOnNull ,
35- FunctionDeterminismSpecifier , FunctionParallel , Ident , MySQLColumnPosition , ObjectName ,
36- OperateFunctionArg , OrderByExpr , ProjectionSelect , SequenceOptions , SqlOption , Tag , Value ,
37- ValueWithSpan ,
38- } ;
32+ use crate :: ast:: { display_comma_separated, display_separated, CatalogSyncNamespaceMode , CommentDef , CreateFunctionBody , CreateFunctionUsing , DataType , Expr , FunctionBehavior , FunctionCalledOnNull , FunctionDeterminismSpecifier , FunctionParallel , Ident , MySQLColumnPosition , ObjectName , OperateFunctionArg , OrderByExpr , ProjectionSelect , SequenceOptions , SqlOption , StorageSerializationPolicy , Tag , Value , ValueWithSpan } ;
3933use crate :: keywords:: Keyword ;
4034use crate :: tokenizer:: Token ;
4135
@@ -2272,3 +2266,109 @@ impl fmt::Display for CreateConnector {
22722266 Ok ( ( ) )
22732267 }
22742268}
2269+
2270+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2271+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2272+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2273+ pub struct CreateSnowflakeDatabase {
2274+ pub or_replace : bool ,
2275+ pub transient : bool ,
2276+ pub if_not_exists : bool ,
2277+ pub name : ObjectName ,
2278+ pub clone : Option < ObjectName > ,
2279+ pub data_retention_time_in_days : Option < u64 > ,
2280+ pub max_data_extension_time_in_days : Option < u64 > ,
2281+ pub external_volume : Option < String > ,
2282+ pub catalog : Option < String > ,
2283+ pub replace_invalid_characters : Option < bool > ,
2284+ pub default_ddl_collation : Option < String > ,
2285+ pub storage_serialization_policy : Option < StorageSerializationPolicy > ,
2286+ pub comment : Option < String > ,
2287+ pub catalog_sync : Option < String > ,
2288+ pub catalog_sync_namespace_mode : Option < CatalogSyncNamespaceMode > ,
2289+ pub catalog_sync_namespace_flatten_delimiter : Option < String > ,
2290+ pub with_tags : Option < Vec < Tag > > ,
2291+ pub with_contacts : Option < Vec < ( String , String ) > > ,
2292+ }
2293+
2294+ impl fmt:: Display for CreateSnowflakeDatabase {
2295+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2296+ write ! (
2297+ f,
2298+ "CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}" ,
2299+ or_replace = if self . or_replace { "OR REPLACE " } else { "" } ,
2300+ transient = if self . transient { "TRANSIENT " } else { "" } ,
2301+ if_not_exists = if self . if_not_exists { "IF NOT EXISTS " } else { "" } ,
2302+ name = self . name,
2303+ ) ?;
2304+
2305+ if let Some ( clone) = & self . clone {
2306+ write ! ( f, " CLONE {clone}" ) ?;
2307+ }
2308+
2309+ if let Some ( value) = self . data_retention_time_in_days {
2310+ write ! ( f, " DATA_RETENTION_TIME_IN_DAYS = {value}" ) ?;
2311+ }
2312+
2313+ if let Some ( value) = self . max_data_extension_time_in_days {
2314+ write ! ( f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}" ) ?;
2315+ }
2316+
2317+ if let Some ( vol) = & self . external_volume {
2318+ write ! ( f, " EXTERNAL_VOLUME = '{vol}'" ) ?;
2319+ }
2320+
2321+ if let Some ( cat) = & self . catalog {
2322+ write ! ( f, " CATALOG = '{cat}'" ) ?;
2323+ }
2324+
2325+ if let Some ( true ) = self . replace_invalid_characters {
2326+ write ! ( f, " REPLACE_INVALID_CHARACTERS = TRUE" ) ?;
2327+ } else if let Some ( false ) = self . replace_invalid_characters {
2328+ write ! ( f, " REPLACE_INVALID_CHARACTERS = FALSE" ) ?;
2329+ }
2330+
2331+ if let Some ( collation) = & self . default_ddl_collation {
2332+ write ! ( f, " DEFAULT_DDL_COLLATION = '{collation}'" ) ?;
2333+ }
2334+
2335+ if let Some ( policy) = & self . storage_serialization_policy {
2336+ write ! ( f, " STORAGE_SERIALIZATION_POLICY = {policy}" ) ?;
2337+ }
2338+
2339+ if let Some ( comment) = & self . comment {
2340+ write ! ( f, " COMMENT = '{comment}'" ) ?;
2341+ }
2342+
2343+ if let Some ( sync) = & self . catalog_sync {
2344+ write ! ( f, " CATALOG_SYNC = '{sync}'" ) ?;
2345+ }
2346+
2347+ if let Some ( mode) = & self . catalog_sync_namespace_mode {
2348+ write ! ( f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}" ) ?;
2349+ }
2350+
2351+ if let Some ( delim) = & self . catalog_sync_namespace_flatten_delimiter {
2352+ write ! ( f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'" ) ?;
2353+ }
2354+
2355+ if let Some ( tags) = & self . with_tags {
2356+ write ! ( f, " WITH TAG ({})" , display_comma_separated( tags) ) ?;
2357+ }
2358+
2359+ if let Some ( contacts) = & self . with_contacts {
2360+ write ! (
2361+ f,
2362+ " WITH CONTACT ({})" ,
2363+ display_comma_separated(
2364+ & contacts
2365+ . iter( )
2366+ . map( |( purpose, contact) | format!( "{purpose} = {contact}" ) )
2367+ . collect:: <Vec <_>>( )
2368+ )
2369+ ) ?;
2370+ }
2371+
2372+ Ok ( ( ) )
2373+ }
2374+ }
0 commit comments