Skip to content

Incorrect Stringification of indexMethod in addToOperatorFamily #1469

Description

@brenoepics

Describe the bug

When passing an object as the indexMethod argument to addToOperatorFamily, the resulting SQL statement contains USING [object Object] if the object is not properly stringified. This is due to direct string interpolation for indexMethod.

export type Name = string | { schema?: string; name: string };

return `ALTER OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod} ADD
${operatorListStr};`;

Example:

const statement = addToOperatorFamily(options1)(
  'integer_ops',
  { schema: 'myschema', name: 'btree' },
  [
    {
      type: 'operator',
      number: 1,
      name: '<',
      params: [{ type: 'int4' }, { type: 'int2' }],
    },
  ]
);
// statement contains: 'USING [object Object]'

Test Case:

it('should coerce object indexMethod to [object Object] if not handled', () => {
  const addToOperatorFamilyFn = addToOperatorFamily(options1);
  const statement = addToOperatorFamilyFn(
    'integer_ops',
    { schema: 'myschema', name: 'btree' },
    [
      {
        type: 'operator',
        number: 1,
        name: '<',
        params: [{ type: 'int4' }, { type: 'int2' }],
      },
    ]
  );
  expect(statement).toContain('USING [object Object]');
});

we need to handle it when it contains schema.

Steps to reproduce

  1. Call addToOperatorFamily with an object for indexMethod, e.g. { schema: 'myschema', name: 'btree' }.
  2. Observe the generated SQL statement.

Logs

No response

System Info

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions