Skip to content

Commit 6c81d4b

Browse files
authored
Merge pull request #129 from tomquist/support-opclass
Add support for index opclass
2 parents 4e0007c + 6d9db73 commit 6c81d4b

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
@@ -26287,6 +26287,73 @@ exports[`kitchen sink indexes 9`] = `
2628726287

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

26290+
exports[`kitchen sink indexes 11`] = `
26291+
{
26292+
"RawStmt": {
26293+
"stmt": {
26294+
"IndexStmt": {
26295+
"accessMethod": "gin",
26296+
"concurrent": true,
26297+
"idxname": "idx_with_operator",
26298+
"indexParams": [
26299+
{
26300+
"IndexElem": {
26301+
"name": "name",
26302+
"nulls_ordering": "SORTBY_NULLS_DEFAULT",
26303+
"opclass": [
26304+
{
26305+
"String": {
26306+
"str": "gin_trgm_ops",
26307+
},
26308+
},
26309+
],
26310+
"opclassopts": [
26311+
{
26312+
"DefElem": {
26313+
"arg": {
26314+
"Integer": {
26315+
"ival": 32,
26316+
},
26317+
},
26318+
"defaction": "DEFELEM_UNSPEC",
26319+
"defname": "param1",
26320+
"location": 624,
26321+
},
26322+
},
26323+
{
26324+
"DefElem": {
26325+
"arg": {
26326+
"String": {
26327+
"str": "true",
26328+
},
26329+
},
26330+
"defaction": "DEFELEM_UNSPEC",
26331+
"defname": "param2",
26332+
"location": 637,
26333+
},
26334+
},
26335+
],
26336+
"ordering": "SORTBY_DEFAULT",
26337+
},
26338+
},
26339+
],
26340+
"relation": {
26341+
"inh": true,
26342+
"location": 575,
26343+
"relname": "merkle_tree",
26344+
"relpersistence": "p",
26345+
"schemaname": "boom",
26346+
},
26347+
},
26348+
},
26349+
"stmt_len": 127,
26350+
"stmt_location": 526,
26351+
},
26352+
}
26353+
`;
26354+
26355+
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 ) );"`;
26356+
2629026357
exports[`kitchen sink insert 1`] = `
2629126358
{
2629226359
"RawStmt": {

packages/deparser/src/deparser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,14 @@ export default class Deparser {
15511551
const output = [];
15521552
if (node.name) {
15531553
output.push(node.name);
1554+
if (node.opclass && node.opclass.length) {
1555+
output.push(this.deparse(node.opclass[0]));
1556+
}
1557+
if (node.opclassopts && node.opclassopts.length) {
1558+
output.push('(');
1559+
output.push(node.opclassopts.map((opclassopt) => this.deparse(opclassopt)).join(', '));
1560+
output.push(')');
1561+
}
15541562
if (node.ordering === 'SORTBY_DESC') {
15551563
output.push('DESC');
15561564
} else if (node.ordering === 'SORTBY_ASC') {

0 commit comments

Comments
 (0)