Skip to content

Commit

Permalink
feat: support transaction begin
Browse files Browse the repository at this point in the history
  • Loading branch information
cvng committed Jan 20, 2024
1 parent bbc24cc commit 39e5cc2
Show file tree
Hide file tree
Showing 40 changed files with 11,247 additions and 1 deletion.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[alias]
snap = "insta test"
xtask = "run --package xtask --"
1 change: 1 addition & 0 deletions crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ fn custom_handlers(node: &Node) -> TokenStream {
},
"TransactionStmt" => quote! {
match n.kind() {
protobuf::TransactionStmtKind::TransStmtBegin => tokens.push(TokenProperty::from(Token::BeginP)),
protobuf::TransactionStmtKind::TransStmtCommit => tokens.push(TokenProperty::from(Token::Commit)),
_ => panic!("Unknown TransactionStmt {:#?}", n.kind())
}
Expand Down
1 change: 0 additions & 1 deletion crates/parser/tests/skipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
advisory_lock
aggregates
alter_generic
alter_operator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: "--\n-- ADVISORY LOCKS\n--\n\nBEGIN;"
---
Parse {
cst: SourceFile@0..31
SqlComment@0..2 "--"
Newline@2..3 "\n"
SqlComment@3..20 "-- ADVISORY LOCKS"
Newline@20..21 "\n"
SqlComment@21..23 "--"
Newline@23..25 "\n\n"
TransactionStmt@25..31
BeginP@25..30 "BEGIN"
Ascii59@30..31 ";"
,
errors: [],
stmts: [
RawStmt {
stmt: TransactionStmt(
TransactionStmt {
kind: TransStmtBegin,
options: [],
savepoint_name: "",
gid: "",
chain: false,
},
),
range: 24..30,
},
],
}
363 changes: 363 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/advisory_lock@10.snap

Large diffs are not rendered by default.

487 changes: 487 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/advisory_lock@11.snap

Large diffs are not rendered by default.

361 changes: 361 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/advisory_lock@12.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: ROLLBACK;
---
Parse {
cst: SourceFile@0..9
Rollback@0..8 "ROLLBACK"
Ascii59@8..9 ";"
,
errors: [],
stmts: [],
}
487 changes: 487 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/advisory_lock@14.snap

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/advisory_lock@15.snap

Large diffs are not rendered by default.

186 changes: 186 additions & 0 deletions crates/parser/tests/snapshots/statements/valid/advisory_lock@16.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: "SELECT count(*) FROM pg_locks WHERE locktype = 'advisory';"
---
Parse {
cst: SourceFile@0..58
SelectStmt@0..58
Select@0..6 "SELECT"
Whitespace@6..7 " "
ResTarget@7..14
FuncCall@7..14
Ident@7..12 "count"
Ascii40@12..13 "("
Ascii42@13..14 "*"
Ascii41@14..15 ")"
Whitespace@15..16 " "
From@16..20 "FROM"
Whitespace@20..21 " "
RangeVar@21..29
Ident@21..29 "pg_locks"
Whitespace@29..30 " "
Where@30..35 "WHERE"
Whitespace@35..36 " "
AExpr@36..57
ColumnRef@36..44
Ident@36..44 "locktype"
Whitespace@44..45 " "
Ascii61@45..46 "="
Whitespace@46..47 " "
AConst@47..57
Sconst@47..57 "'advisory'"
Ascii59@57..58 ";"
,
errors: [],
stmts: [
RawStmt {
stmt: SelectStmt(
SelectStmt {
distinct_clause: [],
into_clause: None,
target_list: [
Node {
node: Some(
ResTarget(
ResTarget {
name: "",
indirection: [],
val: Some(
Node {
node: Some(
FuncCall(
FuncCall {
funcname: [
Node {
node: Some(
String(
String {
sval: "count",
},
),
),
},
],
args: [],
agg_order: [],
agg_filter: None,
over: None,
agg_within_group: false,
agg_star: true,
agg_distinct: false,
func_variadic: false,
funcformat: CoerceExplicitCall,
location: 7,
},
),
),
},
),
location: 7,
},
),
),
},
],
from_clause: [
Node {
node: Some(
RangeVar(
RangeVar {
catalogname: "",
schemaname: "",
relname: "pg_locks",
inh: true,
relpersistence: "p",
alias: None,
location: 21,
},
),
),
},
],
where_clause: Some(
Node {
node: Some(
AExpr(
AExpr {
kind: AexprOp,
name: [
Node {
node: Some(
String(
String {
sval: "=",
},
),
),
},
],
lexpr: Some(
Node {
node: Some(
ColumnRef(
ColumnRef {
fields: [
Node {
node: Some(
String(
String {
sval: "locktype",
},
),
),
},
],
location: 36,
},
),
),
},
),
rexpr: Some(
Node {
node: Some(
AConst(
AConst {
isnull: false,
location: 47,
val: Some(
Sval(
String {
sval: "advisory",
},
),
),
},
),
),
},
),
location: 45,
},
),
),
},
),
group_clause: [],
group_distinct: false,
having_clause: None,
window_clause: [],
values_lists: [],
sort_clause: [],
limit_offset: None,
limit_count: None,
limit_option: Default,
locking_clause: [],
with_clause: None,
op: SetopNone,
all: false,
larg: None,
rarg: None,
},
),
range: 0..57,
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: crates/parser/tests/statement_parser_test.rs
description: BEGIN;
---
Parse {
cst: SourceFile@0..6
TransactionStmt@0..6
BeginP@0..5 "BEGIN"
Ascii59@5..6 ";"
,
errors: [],
stmts: [
RawStmt {
stmt: TransactionStmt(
TransactionStmt {
kind: TransStmtBegin,
options: [],
savepoint_name: "",
gid: "",
chain: false,
},
),
range: 0..5,
},
],
}
Loading

0 comments on commit 39e5cc2

Please sign in to comment.