Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// 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 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"
`;
Loading