@@ -954,6 +954,13 @@ impl fmt::Display for CommentObject {
954954 }
955955}
956956
957+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
958+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
959+ pub enum Password {
960+ Password ( Expr ) ,
961+ NullPassword ,
962+ }
963+
957964/// A top-level statement (SELECT, INSERT, CREATE, etc.)
958965#[ allow( clippy:: large_enum_variant) ]
959966#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
@@ -1109,6 +1116,27 @@ pub enum Statement {
11091116 unique : bool ,
11101117 if_not_exists : bool ,
11111118 } ,
1119+ /// CREATE ROLE
1120+ CreateRole {
1121+ names : Vec < ObjectName > ,
1122+ if_not_exists : bool ,
1123+ // Postgres
1124+ login : Option < bool > ,
1125+ inherit : Option < bool > ,
1126+ bypassrls : Option < bool > ,
1127+ password : Option < Password > ,
1128+ superuser : Option < bool > ,
1129+ create_db : Option < bool > ,
1130+ create_role : Option < bool > ,
1131+ replication : Option < bool > ,
1132+ connection_limit : Option < Expr > ,
1133+ valid_until : Option < Expr > ,
1134+ in_role : Vec < Ident > ,
1135+ role : Vec < Ident > ,
1136+ admin : Vec < Ident > ,
1137+ // MSSQL
1138+ authorization_owner : Option < ObjectName > ,
1139+ } ,
11121140 /// ALTER TABLE
11131141 AlterTable {
11141142 /// Table name
@@ -1963,6 +1991,90 @@ impl fmt::Display for Statement {
19631991 table_name = table_name,
19641992 columns = display_separated( columns, "," )
19651993 ) ,
1994+ Statement :: CreateRole {
1995+ names,
1996+ if_not_exists,
1997+ inherit,
1998+ login,
1999+ bypassrls,
2000+ password,
2001+ create_db,
2002+ create_role,
2003+ superuser,
2004+ replication,
2005+ connection_limit,
2006+ valid_until,
2007+ in_role,
2008+ role,
2009+ admin,
2010+ authorization_owner,
2011+ } => {
2012+ write ! (
2013+ f,
2014+ "CREATE ROLE {if_not_exists}{names}{superuser}{create_db}{create_role}{inherit}{login}{replication}{bypassrls}" ,
2015+ if_not_exists = if * if_not_exists { "IF NOT EXISTS " } else { "" } ,
2016+ names = display_separated( names, ", " ) ,
2017+ superuser = match * superuser {
2018+ Some ( true ) => " SUPERUSER" ,
2019+ Some ( false ) => " NOSUPERUSER" ,
2020+ None => ""
2021+ } ,
2022+ create_db = match * create_db {
2023+ Some ( true ) => " CREATEDB" ,
2024+ Some ( false ) => " NOCREATEDB" ,
2025+ None => ""
2026+ } ,
2027+ create_role = match * create_role {
2028+ Some ( true ) => " CREATEROLE" ,
2029+ Some ( false ) => " NOCREATEROLE" ,
2030+ None => ""
2031+ } ,
2032+ inherit = match * inherit {
2033+ Some ( true ) => " INHERIT" ,
2034+ Some ( false ) => " NOINHERIT" ,
2035+ None => ""
2036+ } ,
2037+ login = match * login {
2038+ Some ( true ) => " LOGIN" ,
2039+ Some ( false ) => " NOLOGIN" ,
2040+ None => ""
2041+ } ,
2042+ replication = match * replication {
2043+ Some ( true ) => " REPLICATION" ,
2044+ Some ( false ) => " NOREPLICATION" ,
2045+ None => ""
2046+ } ,
2047+ bypassrls = match * bypassrls {
2048+ Some ( true ) => " BYPASSRLS" ,
2049+ Some ( false ) => " NOBYPASSRLS" ,
2050+ None => ""
2051+ }
2052+ ) ?;
2053+ if let Some ( limit) = connection_limit {
2054+ write ! ( f, " CONNECTION LIMIT {}" , limit) ?;
2055+ }
2056+ match password {
2057+ Some ( Password :: Password ( pass) ) => write ! ( f, " PASSWORD {}" , pass) ,
2058+ Some ( Password :: NullPassword ) => write ! ( f, " PASSWORD NULL" ) ,
2059+ None => Ok ( ( ) ) ,
2060+ } ?;
2061+ if let Some ( until) = valid_until {
2062+ write ! ( f, " VALID UNTIL {}" , until) ?;
2063+ }
2064+ if !in_role. is_empty ( ) {
2065+ write ! ( f, " IN ROLE {}" , display_comma_separated( in_role) ) ?;
2066+ }
2067+ if !role. is_empty ( ) {
2068+ write ! ( f, " ROLE {}" , display_comma_separated( role) ) ?;
2069+ }
2070+ if !admin. is_empty ( ) {
2071+ write ! ( f, " ADMIN {}" , display_comma_separated( admin) ) ?;
2072+ }
2073+ if let Some ( owner) = authorization_owner {
2074+ write ! ( f, " AUTHORIZATION {}" , owner) ?;
2075+ }
2076+ Ok ( ( ) )
2077+ }
19662078 Statement :: AlterTable { name, operation } => {
19672079 write ! ( f, "ALTER TABLE {} {}" , name, operation)
19682080 }
@@ -2701,6 +2813,7 @@ pub enum ObjectType {
27012813 View ,
27022814 Index ,
27032815 Schema ,
2816+ Role ,
27042817}
27052818
27062819impl fmt:: Display for ObjectType {
@@ -2710,6 +2823,7 @@ impl fmt::Display for ObjectType {
27102823 ObjectType :: View => "VIEW" ,
27112824 ObjectType :: Index => "INDEX" ,
27122825 ObjectType :: Schema => "SCHEMA" ,
2826+ ObjectType :: Role => "ROLE" ,
27132827 } )
27142828 }
27152829}
0 commit comments