_site/cover/pgsqlp_tx.COVER.html

1 %% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com>
2 %%
3 %% Licensed under the Apache License, Version 2.0 (the "License");
4 %% you may not use this file except in compliance with the License.
5 %% You may obtain a copy of the License at
6 %%
7 %% http://www.apache.org/licenses/LICENSE-2.0
8 %%
9 %% Unless required by applicable law or agreed to in writing, software
10 %% distributed under the License is distributed on an "AS IS" BASIS,
11 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 %% See the License for the specific language governing permissions and
13 %% limitations under the License.
14
15
16 -module(pgsqlp_tx).
17
18
19 -export([expression/0]).
20 -import(pgsqlp, [to_atom/1]).
21 -import(scran_branch, [alt/1]).
22 -import(scran_character_complete, [multispace1/0]).
23 -import(scran_character_complete, [tag_no_case/1]).
24 -import(scran_combinator, [ignore_result/1]).
25 -import(scran_combinator, [opt/1]).
26 -import(scran_multi, [separated_list1/2]).
27 -import(scran_result, [kv/2]).
28 -import(scran_sequence, [preceded/2]).
29 -import(scran_sequence, [sequence/1]).
30
31
32 expression() ->
33 18 fun
34 (Input) ->
35 10 (alt([begin_expression(),
36 commit_expression()]))(Input)
37 end.
38
39 begin_expression() ->
40 10 sequence(
41 [kv(action, to_atom(tag_no_case("BEGIN"))),
42 ignore_result(
43 opt(preceded(
44 multispace1(),
45 alt([tag_no_case("WORK"), tag_no_case("TRANSACTION")])))),
46 opt(preceded(
47 multispace1(),
48 separated_list1(
49 multispace1(),
50 alt([kv(isolation_level,
51 preceded(
52 sequence([tag_no_case("ISOLATION LEVEL"),
53 multispace1()]),
54 to_atom(
55 alt([tag_no_case("SERIALIZABLE"),
56 tag_no_case("REPEATABLE READ"),
57 tag_no_case("READ COMMITTED"),
58 tag_no_case("READ UNCOMMITTED")])))),
59
60 kv(read_level,
61 to_atom(
62 alt([tag_no_case("READ WRITE"),
63 tag_no_case("READ ONLY")]))),
64
65 kv(deferrable,
66 to_atom(
67 alt([tag_no_case("NOT DEFERRABLE"),
68 tag_no_case("DEFERRABLE")])))]))))]).
69
70 commit_expression() ->
71 10 sequence([kv(action, to_atom(tag_no_case("COMMIT")))]).
Line Hits Source