mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-03 16:34:19 +01:00
sqlite3-parser: separate boxed Delete struct
This commit is contained in:
@@ -56,10 +56,13 @@ impl Stmt {
|
||||
/// Like `sqlite3_column_count` but more limited
|
||||
pub fn column_count(&self) -> ColumnCount {
|
||||
match self {
|
||||
Self::Delete {
|
||||
returning: Some(returning),
|
||||
..
|
||||
} => column_count(returning),
|
||||
Self::Delete(delete) => {
|
||||
let Delete { returning, .. } = &**delete;
|
||||
match returning {
|
||||
Some(returning) => column_count(returning),
|
||||
None => ColumnCount::None,
|
||||
}
|
||||
}
|
||||
Self::Insert {
|
||||
returning: Some(returning),
|
||||
..
|
||||
@@ -156,11 +159,17 @@ impl Stmt {
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
Self::Delete {
|
||||
order_by: Some(_),
|
||||
limit: None,
|
||||
..
|
||||
} => Err(custom_err!("ORDER BY without LIMIT on DELETE")),
|
||||
Self::Delete(delete) => {
|
||||
let Delete {
|
||||
order_by, limit, ..
|
||||
} = &**delete;
|
||||
if let Some(_) = order_by {
|
||||
if limit.is_none() {
|
||||
return Err(custom_err!("ORDER BY without LIMIT on DELETE"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::Insert {
|
||||
columns: Some(columns),
|
||||
body,
|
||||
|
||||
@@ -305,15 +305,16 @@ impl ToTokens for Stmt {
|
||||
}
|
||||
s.append(TK_RP, None)
|
||||
}
|
||||
Self::Delete {
|
||||
with,
|
||||
tbl_name,
|
||||
indexed,
|
||||
where_clause,
|
||||
returning,
|
||||
order_by,
|
||||
limit,
|
||||
} => {
|
||||
Self::Delete(delete) => {
|
||||
let Delete {
|
||||
with,
|
||||
tbl_name,
|
||||
indexed,
|
||||
where_clause,
|
||||
returning,
|
||||
order_by,
|
||||
limit,
|
||||
} = &**delete;
|
||||
if let Some(with) = with {
|
||||
with.to_tokens(s)?;
|
||||
}
|
||||
|
||||
@@ -141,22 +141,7 @@ pub enum Stmt {
|
||||
args: Option<Vec<String>>, // TODO smol str
|
||||
},
|
||||
/// `DELETE`
|
||||
Delete {
|
||||
/// CTE
|
||||
with: Option<With>,
|
||||
/// `FROM` table name
|
||||
tbl_name: QualifiedName,
|
||||
/// `INDEXED`
|
||||
indexed: Option<Indexed>,
|
||||
/// `WHERE` clause
|
||||
where_clause: Option<Box<Expr>>,
|
||||
/// `RETURNING`
|
||||
returning: Option<Vec<ResultColumn>>,
|
||||
/// `ORDER BY`
|
||||
order_by: Option<Vec<SortedColumn>>,
|
||||
/// `LIMIT`
|
||||
limit: Option<Box<Limit>>,
|
||||
},
|
||||
Delete(Box<Delete>),
|
||||
/// `DETACH DATABASE`: db name
|
||||
Detach(Expr), // TODO distinction between DETACH and DETACH DATABASE
|
||||
/// `DROP INDEX`
|
||||
@@ -276,6 +261,25 @@ pub struct Update {
|
||||
pub limit: Option<Box<Limit>>,
|
||||
}
|
||||
|
||||
/// `DELETE`
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Delete {
|
||||
/// CTE
|
||||
pub with: Option<With>,
|
||||
/// `FROM` table name
|
||||
pub tbl_name: QualifiedName,
|
||||
/// `INDEXED`
|
||||
pub indexed: Option<Indexed>,
|
||||
/// `WHERE` clause
|
||||
pub where_clause: Option<Box<Expr>>,
|
||||
/// `RETURNING`
|
||||
pub returning: Option<Vec<ResultColumn>>,
|
||||
/// `ORDER BY`
|
||||
pub order_by: Option<Vec<SortedColumn>>,
|
||||
/// `LIMIT`
|
||||
pub limit: Option<Box<Limit>>,
|
||||
}
|
||||
|
||||
/// SQL expression
|
||||
// https://sqlite.org/syntax/expr.html
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
||||
Reference in New Issue
Block a user