_site/cover/pgsqlp_copy.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_copy).
17
18
19 -feature(maybe_expr, enable).
20
21
22 -export([expression/0]).
23 -import(pgsqlp, [name/0]).
24 -import(pgsqlp, [t/1]).
25 -import(pgsqlp, [to_atom/1]).
26 -import(scran_branch, [alt/1]).
27 -import(scran_character_complete, [multispace1/0]).
28 -import(scran_character_complete, [tag/1]).
29 -import(scran_character_complete, [tag_no_case/1]).
30 -import(scran_combinator, [opt/1]).
31 -import(scran_multi, [separated_list1/2]).
32 -import(scran_result, [kv/2]).
33 -import(scran_sequence, [delimited/3]).
34 -import(scran_sequence, [preceded/2]).
35 -import(scran_sequence, [sequence/1]).
36 -include_lib("kernel/include/logger.hrl").
37
38
39 expression() ->
40 18 fun
41 (Input) ->
42 10 (sequence(
43 [kv(action, to_atom(tag_no_case("COPY"))),
44 alt(
45 [sequence(
46 [preceded(
47 multispace1(),
48 table_name()),
49 opt(preceded(
50 multispace1(),
51 delimited(tag("("),
52 pgsqlp_scalar:column_references(),
53 tag(")"))))]),
54 pgsqlp_scalar:expression()]),
55 to()]))(Input)
56 end.
57
58
59 to() ->
60 10 fun
61 (Input) ->
62 2 (sequence(
63 [preceded(
64 sequence([multispace1(),
65 tag_no_case("TO"),
66 multispace1()]),
67 alt([kv(filename, delimited(tag("'"), name(), tag("'"))),
68
69 kv(program,
70 preceded(
71 tag_no_case("PROGRAM"),
72 preceded(
73 multispace1(),
74 delimited(tag("'"), name(), tag("'"))))),
75
76 t(tag_no_case("STDOUT"))]))]))(Input)
77 end.
78
79
80 table_name() ->
81 10 fun
82 (Input) ->
83 2 (kv(?FUNCTION_NAME,
84 separated_list1(
85 tag("."),
86 name())))(Input)
87 end.
Line Hits Source