Skip to content

Commit d2d09b9

Browse files
committed
Upgrade to sqlparser-rs 0.56.0
Notes: In v0.55 of sqlparser-rs, the `ObjectName` structure has been changed as shown below. Here is now to migrate. ```diff - pub struct ObjectName(pub Vec<Ident>); + pub struct ObjectName(pub Vec<ObjectNamePart>) ``` Therefore, when using the `parse_sql` function, the data structure of the table name in the return value will change. Previously: ```json { "value": "employee", "quote_style": null, "span": { "start": { "line": 4, "column": 10 }, "end": { "line": 4, "column": 18 } } } ``` Now: ```json { "Identifier": { "value": "employee", "quote_style": null, "span": { "start": { "line": 4, "column": 10 }, "end": { "line": 4, "column": 18 } } } } ```
1 parent a673beb commit d2d09b9

File tree

5 files changed

+93
-12
lines changed

5 files changed

+93
-12
lines changed

CHANGELOG.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1+
# 0.1.56
2+
3+
- Upgrade to sqlparser-rs 0.56.0
4+
5+
In v0.55 of sqlparser-rs, the `ObjectName` structure has been changed as shown below. Here is now to migrate.
6+
7+
```diff
8+
- pub struct ObjectName(pub Vec<Ident>);
9+
+ pub struct ObjectName(pub Vec<ObjectNamePart>)
10+
```
11+
12+
Therefore, when using the `parse_sql` function, the data structure of the table name in the return value will change.
13+
14+
Previously:
15+
16+
```json
17+
{
18+
"value": "employee",
19+
"quote_style": null,
20+
"span":
21+
{
22+
"start":
23+
{
24+
"line": 4,
25+
"column": 10
26+
},
27+
"end":
28+
{
29+
"line": 4,
30+
"column": 18
31+
}
32+
}
33+
}
34+
```
35+
36+
Now:
37+
38+
39+
```json
40+
{
41+
"Identifier":
42+
{
43+
"value": "employee",
44+
"quote_style": null,
45+
"span":
46+
{
47+
"start":
48+
{
49+
"line": 4,
50+
"column": 10
51+
},
52+
"end":
53+
{
54+
"line": 4,
55+
"column": 18
56+
}
57+
}
58+
}
59+
}
60+
```
161

262
# 0.1.36
363

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqloxide"
3-
version = "0.1.54"
3+
version = "0.1.56"
44
authors = ["Will Eaton <[email protected]>"]
55
edition = "2021"
66

@@ -17,5 +17,5 @@ version = "0.22"
1717
features = ["extension-module"]
1818

1919
[dependencies.sqlparser]
20-
version = "0.54.0"
20+
version = "0.56.0"
2121
features = ["serde", "visitor"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sqloxide"
3-
version = "0.1.54rc2"
3+
version = "0.1.56"
44
authors = [{ name = "Will Eaton", email= "<[email protected]>" }]
55
repository = "https://github.com/wseaton/sqloxide"
66
license = "MIT"

src/visitor.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use pyo3::prelude::*;
66
use serde::Serialize;
77

88
use sqlparser::ast::{
9-
Statement, {visit_expressions, visit_expressions_mut, visit_relations, visit_relations_mut},
9+
Statement, ObjectNamePart, {visit_expressions, visit_expressions_mut, visit_relations, visit_relations_mut},
1010
};
1111

1212
// Refactored function for handling depythonization
@@ -61,7 +61,8 @@ pub fn mutate_relations(_py: Python, parsed_query: &Bound<'_, PyAny>, func: &Bou
6161
for statement in &mut statements {
6262
visit_relations_mut(statement, |table| {
6363
for section in &mut table.0 {
64-
let val = match func.call1((section.value.clone(),)) {
64+
let ObjectNamePart::Identifier(ident) = section;
65+
let val = match func.call1((ident.value.clone(),)) {
6566
Ok(val) => val,
6667
Err(e) => {
6768
let msg = e.to_string();
@@ -71,7 +72,7 @@ pub fn mutate_relations(_py: Python, parsed_query: &Bound<'_, PyAny>, func: &Bou
7172
}
7273
};
7374

74-
section.value = val.to_string();
75+
ident.value = val.to_string();
7576
}
7677
ControlFlow::Continue(())
7778
});

tests/test_sqloxide.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ def test_extract_relations():
4343
ast = parse_sql(sql=SQL, dialect="ansi")
4444

4545
assert extract_relations(parsed_query=ast)[0][0] == {
46-
"value": "employee",
47-
"quote_style": None,
46+
"Identifier": {
47+
"value": "employee",
48+
"quote_style": None,
49+
"span": {
50+
"start": {"line": 4, "column": 10},
51+
"end": {"line": 4, "column": 18},
52+
},
53+
}
4854
}
4955

5056

@@ -54,7 +60,7 @@ def func(x):
5460

5561
ast = parse_sql(sql=SQL, dialect="ansi")
5662
assert mutate_relations(parsed_query=ast, func=func) == [
57-
'SELECT employee.first_name, employee.last_name, c.start_time, c.end_time, call_outcome.outcome_text FROM employee JOIN "call2"."call2"."call2" AS c ON c.employee_id = employee.id JOIN call2_outcome ON c.call_outcome_id = call_outcome.id ORDER BY c.start_time ASC'
63+
'SELECT employee.first_name, employee.last_name, c.start_time, c.end_time, call_outcome.outcome_text FROM employee INNER JOIN "call2"."call2"."call2" AS c ON c.employee_id = employee.id INNER JOIN call2_outcome ON c.call_outcome_id = call_outcome.id ORDER BY c.start_time ASC'
5864
]
5965

6066

@@ -81,7 +87,7 @@ def func(x):
8187
ast = parse_sql(sql=SQL, dialect="ansi")
8288
result = mutate_expressions(parsed_query=ast, func=func)
8389
assert result == [
84-
'SELECT EMPLOYEE.FIRST_NAME, EMPLOYEE.LAST_NAME, C.START_TIME, C.END_TIME, CALL_OUTCOME.OUTCOME_TEXT FROM employee JOIN "call"."call"."call" AS c ON C.EMPLOYEE_ID = EMPLOYEE.ID JOIN call_outcome ON C.CALL_OUTCOME_ID = CALL_OUTCOME.ID ORDER BY C.START_TIME ASC'
90+
'SELECT EMPLOYEE.FIRST_NAME, EMPLOYEE.LAST_NAME, C.START_TIME, C.END_TIME, CALL_OUTCOME.OUTCOME_TEXT FROM employee INNER JOIN "call"."call"."call" AS c ON C.EMPLOYEE_ID = EMPLOYEE.ID INNER JOIN call_outcome ON C.CALL_OUTCOME_ID = CALL_OUTCOME.ID ORDER BY C.START_TIME ASC'
8591
]
8692

8793

@@ -93,7 +99,21 @@ def test_extract_expressions():
9399

94100
assert exprs[0] == {
95101
"CompoundIdentifier": [
96-
{"value": "employee", "quote_style": None},
97-
{"value": "first_name", "quote_style": None},
102+
{
103+
"value": "employee",
104+
"quote_style": None,
105+
"span": {
106+
"end": {"column": 20, "line": 2},
107+
"start": {"column": 12, "line": 2},
108+
},
109+
},
110+
{
111+
"value": "first_name",
112+
"quote_style": None,
113+
"span": {
114+
"end": {"column": 31, "line": 2},
115+
"start": {"column": 21, "line": 2},
116+
},
117+
},
98118
]
99119
}

0 commit comments

Comments
 (0)