mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 11:14:20 +01:00
sqlite3-parser: separate boxed CreateVirtualTable struct
This commit is contained in:
@@ -3,7 +3,7 @@ use fallible_iterator::FallibleIterator;
|
||||
use super::{Error, Parser};
|
||||
use crate::parser::ast::fmt::ToTokens;
|
||||
use crate::parser::{
|
||||
ast::{Cmd, Name, ParameterInfo, QualifiedName, Stmt},
|
||||
ast::{Cmd, ParameterInfo, Stmt},
|
||||
ParserError,
|
||||
};
|
||||
|
||||
@@ -73,20 +73,12 @@ fn vtab_args() -> Result<(), Error> {
|
||||
body TEXT CHECK(length(body)<10240)
|
||||
);";
|
||||
let r = parse_cmd(sql);
|
||||
let Cmd::Stmt(Stmt::CreateVirtualTable {
|
||||
tbl_name: QualifiedName {
|
||||
name: Name(tbl_name),
|
||||
..
|
||||
},
|
||||
module_name: Name(module_name),
|
||||
args: Some(args),
|
||||
..
|
||||
}) = r
|
||||
else {
|
||||
let Cmd::Stmt(Stmt::CreateVirtualTable(create_virtual_table)) = r else {
|
||||
panic!("unexpected AST")
|
||||
};
|
||||
assert_eq!(tbl_name, "mail");
|
||||
assert_eq!(module_name, "fts3");
|
||||
assert_eq!(create_virtual_table.tbl_name.name, "mail");
|
||||
assert_eq!(create_virtual_table.module_name.0, "fts3");
|
||||
let args = create_virtual_table.args.as_ref().unwrap();
|
||||
assert_eq!(args.len(), 2);
|
||||
assert_eq!(args[0], "subject VARCHAR(256) NOT NULL");
|
||||
assert_eq!(args[1], "body TEXT CHECK(length(body)<10240)");
|
||||
|
||||
@@ -283,12 +283,13 @@ impl ToTokens for Stmt {
|
||||
s.append(TK_AS, None)?;
|
||||
select.to_tokens(s)
|
||||
}
|
||||
Self::CreateVirtualTable {
|
||||
if_not_exists,
|
||||
tbl_name,
|
||||
module_name,
|
||||
args,
|
||||
} => {
|
||||
Self::CreateVirtualTable(create_virtual_table) => {
|
||||
let CreateVirtualTable {
|
||||
if_not_exists,
|
||||
tbl_name,
|
||||
module_name,
|
||||
args,
|
||||
} = &**create_virtual_table;
|
||||
s.append(TK_CREATE, None)?;
|
||||
s.append(TK_VIRTUAL, None)?;
|
||||
s.append(TK_TABLE, None)?;
|
||||
|
||||
@@ -130,16 +130,7 @@ pub enum Stmt {
|
||||
select: Box<Select>,
|
||||
},
|
||||
/// `CREATE VIRTUAL TABLE`
|
||||
CreateVirtualTable {
|
||||
/// `IF NOT EXISTS`
|
||||
if_not_exists: bool,
|
||||
/// table name
|
||||
tbl_name: QualifiedName,
|
||||
/// module
|
||||
module_name: Name,
|
||||
/// args
|
||||
args: Option<Vec<String>>, // TODO smol str
|
||||
},
|
||||
CreateVirtualTable(Box<CreateVirtualTable>),
|
||||
/// `DELETE`
|
||||
Delete(Box<Delete>),
|
||||
/// `DETACH DATABASE`: db name
|
||||
@@ -197,7 +188,17 @@ pub enum Stmt {
|
||||
/// `UPDATE`
|
||||
Update(Box<Update>),
|
||||
/// `VACUUM`: database name, into expr
|
||||
Vacuum(Option<Name>, Option<Expr>),
|
||||
/// `CREATE VIRTUAL TABLE`
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CreateVirtualTable {
|
||||
/// `IF NOT EXISTS`
|
||||
pub if_not_exists: bool,
|
||||
/// table name
|
||||
pub tbl_name: QualifiedName,
|
||||
/// module name
|
||||
pub module_name: Name,
|
||||
/// args
|
||||
pub args: Option<Vec<String>>, // TODO smol str
|
||||
}
|
||||
|
||||
/// `CREATE TRIGGER
|
||||
|
||||
@@ -1329,15 +1329,15 @@ kwcolumn_opt ::= COLUMNKW.
|
||||
cmd ::= create_vtab(X). {self.ctx.stmt = Some(X);}
|
||||
cmd ::= create_vtab(X) LP vtabarglist RP. {
|
||||
let mut stmt = X;
|
||||
if let Stmt::CreateVirtualTable{ ref mut args, .. } = stmt {
|
||||
*args = self.ctx.module_args();
|
||||
if let Stmt::CreateVirtualTable(ref mut create_virtual_table) = stmt {
|
||||
create_virtual_table.args = self.ctx.module_args();
|
||||
}
|
||||
self.ctx.stmt = Some(stmt);
|
||||
}
|
||||
%type create_vtab {Stmt}
|
||||
create_vtab(A) ::= createkw VIRTUAL TABLE ifnotexists(E)
|
||||
fullname(X) USING nm(Z). {
|
||||
A = Stmt::CreateVirtualTable{ if_not_exists: E, tbl_name: X, module_name: Z, args: None };
|
||||
A = Stmt::CreateVirtualTable(Box::new(CreateVirtualTable{ if_not_exists: E, tbl_name: X, module_name: Z, args: None }));
|
||||
}
|
||||
vtabarglist ::= vtabarg.
|
||||
vtabarglist ::= vtabarglist COMMA vtabarg.
|
||||
|
||||
Reference in New Issue
Block a user