diff --git a/core/src/sql/fmt.rs b/core/src/sql/fmt.rs index e6cf7730..ef98ee4f 100644 --- a/core/src/sql/fmt.rs +++ b/core/src/sql/fmt.rs @@ -293,8 +293,8 @@ mod tests { #[test] fn pretty_define_query() { let query = parse("DEFINE TABLE test SCHEMAFULL PERMISSIONS FOR create, update, delete NONE FOR select WHERE public = true;").unwrap(); - assert_eq!(format!("{}", query), "DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS FOR select WHERE public = true, FOR create, update, delete NONE;"); - assert_eq!(format!("{:#}", query), "DEFINE TABLE test TYPE ANY SCHEMAFULL\n\tPERMISSIONS\n\t\tFOR select\n\t\t\tWHERE public = true\n\t\tFOR create, update, delete NONE\n;"); + assert_eq!(format!("{}", query), "DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS FOR select WHERE public = true, FOR create, update, delete NONE;"); + assert_eq!(format!("{:#}", query), "DEFINE TABLE test TYPE NORMAL SCHEMAFULL\n\tPERMISSIONS\n\t\tFOR select\n\t\t\tWHERE public = true\n\t\tFOR create, update, delete NONE\n;"); } #[test] diff --git a/core/src/syn/parser/stmt/define.rs b/core/src/syn/parser/stmt/define.rs index bee3776f..12aae05f 100644 --- a/core/src/syn/parser/stmt/define.rs +++ b/core/src/syn/parser/stmt/define.rs @@ -646,6 +646,8 @@ impl Parser<'_> { ..Default::default() }; + let mut kind: Option = None; + loop { match self.peek_kind() { t!("COMMENT") => { @@ -661,15 +663,15 @@ impl Parser<'_> { match self.peek_kind() { t!("NORMAL") => { self.pop_peek(); - res.kind = TableType::Normal; + kind = Some(TableType::Normal); } t!("RELATION") => { self.pop_peek(); - res.kind = TableType::Relation(self.parse_relation_schema()?); + kind = Some(TableType::Relation(self.parse_relation_schema()?)); } t!("ANY") => { self.pop_peek(); - res.kind = TableType::Any; + kind = Some(TableType::Any); } x => unexpected!(self, x, "`NORMAL`, `RELATION`, or `ANY`"), } @@ -681,6 +683,9 @@ impl Parser<'_> { t!("SCHEMAFULL") => { self.pop_peek(); res.full = true; + if kind.is_none() { + kind = Some(TableType::Normal); + } } t!("PERMISSIONS") => { self.pop_peek(); @@ -708,6 +713,10 @@ impl Parser<'_> { } } + if let Some(kind) = kind { + res.kind = kind; + } + Ok(res) } diff --git a/core/src/syn/parser/test/stmt.rs b/core/src/syn/parser/test/stmt.rs index d9c3681f..31cd5fef 100644 --- a/core/src/syn/parser/test/stmt.rs +++ b/core/src/syn/parser/test/stmt.rs @@ -1410,7 +1410,7 @@ fn parse_define_table() { comment: None, if_not_exists: false, overwrite: false, - kind: TableType::Any, + kind: TableType::Normal, })) ); } diff --git a/core/src/syn/parser/test/streaming.rs b/core/src/syn/parser/test/streaming.rs index 67747057..55618d1f 100644 --- a/core/src/syn/parser/test/streaming.rs +++ b/core/src/syn/parser/test/streaming.rs @@ -279,7 +279,7 @@ fn statements() -> Vec { comment: None, if_not_exists: false, overwrite: false, - kind: TableType::Any, + kind: TableType::Normal, })), Statement::Define(DefineStatement::Event(DefineEventStatement { name: Ident("event".to_owned()), diff --git a/lib/tests/define.rs b/lib/tests/define.rs index 9c64a053..7efed983 100644 --- a/lib/tests/define.rs +++ b/lib/tests/define.rs @@ -179,7 +179,7 @@ async fn define_statement_table_schemafull() -> Result<(), Error> { functions: {}, models: {}, params: {}, - tables: { test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE' }, + tables: { test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE' }, users: {}, }", )?; @@ -208,7 +208,7 @@ async fn define_statement_table_schemaful() -> Result<(), Error> { functions: {}, models: {}, params: {}, - tables: { test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE' }, + tables: { test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE' }, users: {}, }", ); @@ -248,7 +248,7 @@ async fn define_statement_table_foreigntable() -> Result<(), Error> { models: {}, params: {}, tables: { - test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE', + test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE', view: 'DEFINE TABLE view TYPE ANY SCHEMALESS AS SELECT count() FROM test GROUP ALL PERMISSIONS NONE', }, users: {}, @@ -280,7 +280,7 @@ async fn define_statement_table_foreigntable() -> Result<(), Error> { models: {}, params: {}, tables: { - test: 'DEFINE TABLE test TYPE ANY SCHEMAFULL PERMISSIONS NONE', + test: 'DEFINE TABLE test TYPE NORMAL SCHEMAFULL PERMISSIONS NONE', }, users: {}, }",