-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathdeparser-fixes.test.ts.snap
More file actions
181 lines (162 loc) Β· 5.09 KB
/
deparser-fixes.test.ts.snap
File metadata and controls
181 lines (162 loc) Β· 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`plpgsql-deparser bug fixes INTO clause depth-aware scanner should handle INTO STRICT 1`] = `
"DECLARE
v_id integer;
BEGIN
SELECT id INTO STRICT v_id FROM users WHERE email = 'test@example.com';
RETURN v_id;
END"
`;
exports[`plpgsql-deparser bug fixes INTO clause depth-aware scanner should handle INTO with CTE 1`] = `
"DECLARE
v_total integer;
BEGIN
WITH totals AS (
SELECT sum(amount) as total FROM orders
)
SELECT total INTO v_total FROM totals;
RETURN v_total;
END"
`;
exports[`plpgsql-deparser bug fixes INTO clause depth-aware scanner should handle INTO with UNION 1`] = `
"DECLARE
v_count integer;
BEGIN
SELECT count(*) INTO v_count FROM (
SELECT id FROM users
UNION ALL
SELECT id FROM admins
) combined;
RETURN v_count;
END"
`;
exports[`plpgsql-deparser bug fixes INTO clause depth-aware scanner should handle INTO with dollar-quoted strings 1`] = `
"DECLARE
v_result text;
BEGIN
SELECT $tag$some FROM text$tag$ INTO v_result FROM dual;
RETURN v_result;
END"
`;
exports[`plpgsql-deparser bug fixes INTO clause depth-aware scanner should handle INTO with quoted identifiers 1`] = `
"DECLARE
v_name text;
BEGIN
SELECT "user-name" INTO v_name FROM "my-schema"."user-table" WHERE id = 1;
RETURN v_name;
END"
`;
exports[`plpgsql-deparser bug fixes INTO clause depth-aware scanner should insert INTO at correct position for simple SELECT 1`] = `
"DECLARE
v_count integer;
BEGIN
SELECT count(*) INTO v_count FROM users;
RETURN v_count;
END"
`;
exports[`plpgsql-deparser bug fixes INTO clause depth-aware scanner should not insert INTO inside subqueries 1`] = `
"DECLARE
v_result integer;
BEGIN
SELECT (SELECT max(id) FROM orders) INTO v_result FROM users WHERE id = 1;
RETURN v_result;
END"
`;
exports[`plpgsql-deparser bug fixes OUT parameters with SELECT INTO multiple variables should handle SELECT INTO STRICT with multiple OUT parameters 1`] = `
"BEGIN
SELECT u.name, u.email INTO STRICT name, email FROM users u
WHERE u.id = p_id;
RETURN;
END"
`;
exports[`plpgsql-deparser bug fixes OUT parameters with SELECT INTO multiple variables should handle SELECT INTO multiple OUT parameters 1`] = `
"DECLARE
v_token_id uuid;
v_plaintext_token text;
BEGIN
v_plaintext_token := encode(gen_random_bytes(48), 'hex');
v_token_id := uuid_generate_v5(uuid_ns_url(), v_plaintext_token);
INSERT INTO tokens (id, user_id, access_token_hash)
VALUES (v_token_id, p_user_id, digest(v_plaintext_token, 'sha256'));
SELECT tkn.id, tkn.user_id, v_plaintext_token, tkn.access_token_expires_at, tkn.is_verified, tkn.totp_enabled INTO id, user_id, access_token, access_token_expires_at, is_verified, totp_enabled
FROM tokens AS tkn
WHERE tkn.id = v_token_id;
RETURN;
END"
`;
exports[`plpgsql-deparser bug fixes PERFORM SELECT fix should handle PERFORM with complex expressions 1`] = `
"BEGIN
PERFORM set_config('search_path', 'public', true);
PERFORM nextval('my_sequence');
RETURN;
END"
`;
exports[`plpgsql-deparser bug fixes PERFORM SELECT fix should handle PERFORM with subquery 1`] = `
"BEGIN
PERFORM 1 FROM users WHERE id = 1;
RETURN;
END"
`;
exports[`plpgsql-deparser bug fixes PERFORM SELECT fix should strip SELECT keyword from PERFORM statements 1`] = `
"BEGIN
PERFORM pg_sleep(1);
RETURN;
END"
`;
exports[`plpgsql-deparser bug fixes Record field qualification (recfield) should handle OLD and NEW record references 1`] = `
"BEGIN
IF OLD.status <> NEW.status THEN
INSERT INTO audit_log (old_status, new_status) VALUES (OLD.status, NEW.status);
END IF;
RETURN NEW;
END"
`;
exports[`plpgsql-deparser bug fixes Record field qualification (recfield) should handle SELECT INTO with record fields 1`] = `
"BEGIN
SELECT is_active INTO new.is_active FROM users WHERE id = NEW.user_id;
RETURN NEW;
END"
`;
exports[`plpgsql-deparser bug fixes Record field qualification (recfield) should handle custom record types 1`] = `
"DECLARE
r RECORD;
BEGIN
FOR r IN SELECT id, name FROM users LOOP
RAISE NOTICE 'User: % - %', r.id, r.name;
END LOOP;
RETURN;
END"
`;
exports[`plpgsql-deparser bug fixes Record field qualification (recfield) should handle record field assignment 1`] = `
"BEGIN
NEW.created_at := COALESCE(NEW.created_at, now());
NEW.updated_at := now();
NEW.version := COALESCE(OLD.version, 0) + 1;
RETURN NEW;
END"
`;
exports[`plpgsql-deparser bug fixes Record field qualification (recfield) should qualify record fields with parent record name in triggers 1`] = `
"BEGIN
IF NEW.is_active THEN
NEW.updated_at := now();
END IF;
RETURN NEW;
END"
`;
exports[`plpgsql-deparser bug fixes combined scenarios should handle PERFORM with record fields 1`] = `
"BEGIN
PERFORM notify_change(NEW.id, NEW.status);
RETURN NEW;
END"
`;
exports[`plpgsql-deparser bug fixes combined scenarios should handle SELECT INTO with subquery and record fields 1`] = `
"DECLARE
v_count integer;
BEGIN
SELECT count(*) INTO v_count FROM orders WHERE user_id = NEW.user_id;
IF v_count > 100 THEN
NEW.is_premium := true;
END IF;
RETURN NEW;
END"
`;