Skip to content

Commit 0dc7eb6

Browse files
Merge pull request #54 from platformatic/crate-sqlparser-0.58.0
Crate sqlparser upgrade to 0.58.0
2 parents 040c7e0 + 363cbe3 commit 0dc7eb6

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

Cargo.lock

Lines changed: 47 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "Inspects SQL queries to identify the impacted tables/columns"
99
crate-type = ["cdylib", "rlib"]
1010

1111
[dependencies]
12-
sqlparser = { version = "0.52.0", features = ["visitor"] }
12+
sqlparser = { version = "0.58.0", features = ["visitor"] }
1313
serde = { version = "1.0", features = ["derive"] }
1414
wasm-bindgen = "0.2.92"
1515
serde-wasm-bindgen = "0.6.5"

src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Visitor for V {
9999
Statement::Insert(i) => {
100100
self.query_type = QueryType::INSERT;
101101
// The "insert" statement has a table as a target
102-
let table_name = i.table_name.to_string();
102+
let table_name = i.table.to_string();
103103
self.tables.insert(table_name.clone());
104104
self.target_table = table_name.clone();
105105
for i in &i.columns {
@@ -113,6 +113,7 @@ impl Visitor for V {
113113
from: _,
114114
selection: _,
115115
returning: _,
116+
or: _,
116117
} => {
117118
self.query_type = QueryType::UPDATE;
118119
// The "insert" statement has a table as a target
@@ -142,7 +143,16 @@ impl Visitor for V {
142143
let full_name = format!("{table_name}.{column}");
143144
self.columns.insert(full_name);
144145
} else {
145-
let full_name = join(&ident.0);
146+
// Convert ObjectNameParts to Idents for join function
147+
let idents: Vec<Ident> = ident
148+
.0
149+
.iter()
150+
.filter_map(|part| match part {
151+
ObjectNamePart::Identifier(ident) => Some(ident.clone()),
152+
ObjectNamePart::Function(_) => None,
153+
})
154+
.collect();
155+
let full_name = join(&idents);
146156
self.columns.insert(full_name);
147157
}
148158
}
@@ -180,13 +190,15 @@ impl Visitor for V {
180190

181191
fn pre_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow<Self::Break> {
182192
// Relation === table name
183-
let table_name = relation.0[0].value.clone();
184-
self.tables.insert(table_name.clone());
193+
if let Some(ObjectNamePart::Identifier(ident)) = relation.0.first() {
194+
let table_name = ident.value.clone();
195+
self.tables.insert(table_name);
196+
}
185197
ControlFlow::Continue(())
186198
}
187199

188200
fn pre_visit_expr(&mut self, expr: &Expr) -> ControlFlow<Self::Break> {
189-
if let Expr::Wildcard = expr {
201+
if let Expr::Wildcard(_) = expr {
190202
self.columns.insert("*".to_string());
191203
}
192204
if let Expr::Identifier(ident) = expr {

0 commit comments

Comments
 (0)