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
18 changes: 11 additions & 7 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
name: Parser tests
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
parser-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package:
- deparser
- parser
- pgsql-deparser
- pgsql-parser
- plpgsql-deparser
- plpgsql-parser
- pgsql-cli
- proto-parser
- transform
- traverse
- utils
- pg-proto-parser
- '@pgsql/quotes'
- '@pgsql/transform'
steps:
- name: checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions __fixtures__/generated/generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -21330,6 +21330,7 @@
"misc/issues-15.sql": "select \"A\" from \"table_name\"",
"misc/issues-16.sql": "select \"AA\" from \"table_name\"",
"misc/issues-17.sql": "SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t",
"misc/issues-18.sql": "CREATE TABLE test_exclude_where (\n id uuid PRIMARY KEY,\n database_id uuid NOT NULL,\n status text NOT NULL DEFAULT 'pending',\n EXCLUDE USING btree (database_id WITH =)\n WHERE (status = 'pending')\n)",
"misc/inflection-1.sql": "CREATE SCHEMA inflection",
"misc/inflection-2.sql": "GRANT USAGE ON SCHEMA inflection TO PUBLIC",
"misc/inflection-3.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA inflection \n GRANT EXECUTE ON FUNCTIONS TO PUBLIC",
Expand Down
13 changes: 12 additions & 1 deletion __fixtures__/kitchen-sink/misc/issues.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ select "A" from "table_name";
select "AA" from "table_name";

-- https://github.com/constructive-io/pgsql-parser/issues/217
SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t;
SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t;

-- https://github.com/constructive-io/pgsql-parser/issues/287
-- EXCLUDE constraint with WHERE clause (partial exclusion constraint)
-- The deparser drops the WHERE clause from EXCLUDE USING ... WHERE (...)
CREATE TABLE test_exclude_where (
id uuid PRIMARY KEY,
database_id uuid NOT NULL,
status text NOT NULL DEFAULT 'pending',
EXCLUDE USING btree (database_id WITH =)
WHERE (status = 'pending')
);
3 changes: 2 additions & 1 deletion packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ it('misc-issues', async () => {
"misc/issues-14.sql",
"misc/issues-15.sql",
"misc/issues-16.sql",
"misc/issues-17.sql"
"misc/issues-17.sql",
"misc/issues-18.sql"
]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import { FixtureTestUtils } from '../../test-utils';
const fixtures = new FixtureTestUtils();

it('original-tables-foreign_table', async () => {
await fixtures.runFixtureTests([
"original/tables/foreign_table-1.sql"
]);
});
17 changes: 17 additions & 0 deletions packages/deparser/__tests__/kitchen-sink/pretty-formatting.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import { FixtureTestUtils } from '../../test-utils';
const fixtures = new FixtureTestUtils();

it('pretty-formatting', async () => {
await fixtures.runFixtureTests([
"pretty/formatting-1.sql",
"pretty/formatting-2.sql",
"pretty/formatting-3.sql",
"pretty/formatting-4.sql",
"pretty/formatting-5.sql",
"pretty/formatting-6.sql",
"pretty/formatting-7.sql",
"pretty/formatting-8.sql",
"pretty/formatting-9.sql"
]);
});
24 changes: 24 additions & 0 deletions packages/deparser/__tests__/kitchen-sink/pretty-quoting.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

import { FixtureTestUtils } from '../../test-utils';
const fixtures = new FixtureTestUtils();

it('pretty-quoting', async () => {
await fixtures.runFixtureTests([
"pretty/quoting-1.sql",
"pretty/quoting-2.sql",
"pretty/quoting-3.sql",
"pretty/quoting-4.sql",
"pretty/quoting-5.sql",
"pretty/quoting-6.sql",
"pretty/quoting-7.sql",
"pretty/quoting-8.sql",
"pretty/quoting-9.sql",
"pretty/quoting-10.sql",
"pretty/quoting-11.sql",
"pretty/quoting-12.sql",
"pretty/quoting-13.sql",
"pretty/quoting-14.sql",
"pretty/quoting-15.sql",
"pretty/quoting-16.sql"
]);
});
11 changes: 7 additions & 4 deletions packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,7 @@ export class Deparser implements DeparserVisitor {
output.push('VALUES');
const lists = ListUtils.unwrapList(node.valuesLists).map(list => {
const values = ListUtils.unwrapList(list).map(val => this.visit(val as Node, context));
// Put each value on its own line for pretty printing
const indentedValues = values.map(val => context.indent(val));
return '(\n' + indentedValues.join(',\n') + '\n)';
return context.parens(values.join(', '));
});
const indentedTuples = lists.map(tuple => {
if (this.containsMultilineStringLiteral(tuple)) {
Expand Down Expand Up @@ -1892,7 +1890,7 @@ export class Deparser implements DeparserVisitor {
return output.join(' ');
}

let result = mods(typeName, args);
let result = mods(QuoteUtils.quoteIdentifierTypeName(typeName), args);

if (node.arrayBounds && node.arrayBounds.length > 0) {
result += formatArrayBounds(node.arrayBounds);
Expand Down Expand Up @@ -3067,6 +3065,10 @@ export class Deparser implements DeparserVisitor {
});
output.push(`(${exclusionElements.join(', ')})`);
}
if (node.where_clause) {
output.push('WHERE');
output.push(context.parens(this.visit(node.where_clause as any, context)));
}
break;
}

Expand Down Expand Up @@ -11445,3 +11447,4 @@ export class Deparser implements DeparserVisitor {
return stringLiteralRegex.test(content);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,7 @@ BEGIN
note,
updated_at
) VALUES
(
p_org_id,
p_user_id,
p_from_ts,
p_to_ts,
p_currency,
v_orders_scanned,
v_gross,
v_discount,
v_tax,
v_net,
v_avg,
v_top_sku,
v_top_sku_qty,
p_note,
now()
) ON CONFLICT (org_id, user_id, period_from, period_to, currency) DO UPDATE SET
(p_org_id, p_user_id, p_from_ts, p_to_ts, p_currency, v_orders_scanned, v_gross, v_discount, v_tax, v_net, v_avg, v_top_sku, v_top_sku_qty, p_note, now()) ON CONFLICT (org_id, user_id, period_from, period_to, currency) DO UPDATE SET
orders_scanned = excluded.orders_scanned,
gross_total = excluded.gross_total,
discount_total = excluded.discount_total,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,7 @@ CREATE FUNCTION myapp_v2.audit_changes() RETURNS trigger LANGUAGE plpgsql AS $$B
new_data,
changed_at
) VALUES
(
tg_table_name,
tg_op,
to_json(old),
to_json(new),
now()
);
(tg_table_name, tg_op, to_json(old), to_json(new), now());
IF tg_op = 'DELETE' THEN
RETURN old;
END IF;
Expand All @@ -232,11 +226,7 @@ CREATE FUNCTION myapp_v2.update_user_status(
status,
changed_at
) VALUES
(
p_user_id,
p_status,
now()
);
(p_user_id, p_status, now());
RETURN;
END$$;

Expand Down Expand Up @@ -323,10 +313,7 @@ BEGIN
user_id,
created_at
) VALUES
(
new.id,
now()
);
(new.id, now());
ELSE
UPDATE myapp_v2.profiles SET updated_at = now() WHERE user_id = new.id;
END IF;
Expand Down Expand Up @@ -412,10 +399,7 @@ BEGIN
item_id,
processed_at
) VALUES
(
item.id,
now()
);
(item.id, now());
UPDATE myapp_v2.batch_items SET status = 'processed' WHERE id = item.id;
END LOOP;
UPDATE myapp_v2.batches SET status = 'completed',completed_at = now() WHERE id = p_batch_id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`AST to AST to create AST — meta 🤯 1`] = `
"t.nodes.selectStmt({
Expand Down
1 change: 1 addition & 0 deletions packages/proto-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"strfy-js": "^3.1.5"
},
"devDependencies": {
"@pgsql/types": "^17.6.2",
"@types/babel__generator": "^7.27.0",
"makage": "^0.1.8",
"recast": "0.23.11"
Expand Down
Loading
Loading