Skip to content

Commit 6d9db73

Browse files
committed
Add support for index opclass
1 parent f1df82e commit 6d9db73

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

__fixtures__/indexes/custom.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ CREATE UNIQUE INDEX uniq_service_when_not_null
1010
ON schema2.table3 (uid, svc)
1111
WHERE svc IS NOT NULL;
1212

13-
CREATE UNIQUE INDEX new_unique_idx ON new_example(a, b) INCLUDE (c);
13+
CREATE UNIQUE INDEX new_unique_idx ON new_example(a, b) INCLUDE (c);
14+
15+
CREATE INDEX CONCURRENTLY idx_with_operator ON boom.merkle_tree USING GIN ( name gin_trgm_ops ( param1 = 32, param2 = true) );

packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25962,6 +25962,73 @@ exports[`kitchen sink indexes 9`] = `
2596225962

2596325963
exports[`kitchen sink indexes 10`] = `"CREATE UNIQUE INDEX new_unique_idx ON new_example ( a, b ) INCLUDE ( c );"`;
2596425964

25965+
exports[`kitchen sink indexes 11`] = `
25966+
{
25967+
"RawStmt": {
25968+
"stmt": {
25969+
"IndexStmt": {
25970+
"accessMethod": "gin",
25971+
"concurrent": true,
25972+
"idxname": "idx_with_operator",
25973+
"indexParams": [
25974+
{
25975+
"IndexElem": {
25976+
"name": "name",
25977+
"nulls_ordering": "SORTBY_NULLS_DEFAULT",
25978+
"opclass": [
25979+
{
25980+
"String": {
25981+
"str": "gin_trgm_ops",
25982+
},
25983+
},
25984+
],
25985+
"opclassopts": [
25986+
{
25987+
"DefElem": {
25988+
"arg": {
25989+
"Integer": {
25990+
"ival": 32,
25991+
},
25992+
},
25993+
"defaction": "DEFELEM_UNSPEC",
25994+
"defname": "param1",
25995+
"location": 624,
25996+
},
25997+
},
25998+
{
25999+
"DefElem": {
26000+
"arg": {
26001+
"String": {
26002+
"str": "true",
26003+
},
26004+
},
26005+
"defaction": "DEFELEM_UNSPEC",
26006+
"defname": "param2",
26007+
"location": 637,
26008+
},
26009+
},
26010+
],
26011+
"ordering": "SORTBY_DEFAULT",
26012+
},
26013+
},
26014+
],
26015+
"relation": {
26016+
"inh": true,
26017+
"location": 575,
26018+
"relname": "merkle_tree",
26019+
"relpersistence": "p",
26020+
"schemaname": "boom",
26021+
},
26022+
},
26023+
},
26024+
"stmt_len": 127,
26025+
"stmt_location": 526,
26026+
},
26027+
}
26028+
`;
26029+
26030+
exports[`kitchen sink indexes 12`] = `"CREATE INDEX CONCURRENTLY idx_with_operator ON boom.merkle_tree USING GIN ( name gin_trgm_ops ( param1 = 32, param2 = true ) );"`;
26031+
2596526032
exports[`kitchen sink insert 1`] = `
2596626033
{
2596726034
"RawStmt": {

packages/deparser/src/deparser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,14 @@ export default class Deparser {
15481548
const output = [];
15491549
if (node.name) {
15501550
output.push(node.name);
1551+
if (node.opclass && node.opclass.length) {
1552+
output.push(this.deparse(node.opclass[0]));
1553+
}
1554+
if (node.opclassopts && node.opclassopts.length) {
1555+
output.push('(');
1556+
output.push(node.opclassopts.map((opclassopt) => this.deparse(opclassopt)).join(', '));
1557+
output.push(')');
1558+
}
15511559
if (node.ordering === 'SORTBY_DESC') {
15521560
output.push('DESC');
15531561
} else if (node.ordering === 'SORTBY_ASC') {

0 commit comments

Comments
 (0)