Skip to content

Provide escape hatch for sql.fragment and similar entities #285

@gajus

Description

@gajus

Slonik has a concept of SQL fragments (https://github.com/gajus/slonik?tab=readme-ov-file#sqlfragment)

There are effectively fragments of query that would not have a type, e.g.

const whereFragment = sql.fragment`
  WHERE bar = 'baz';
`;

sql.typeAlias('id')`
  SELECT id
  FROM foo
  ${whereFragment}
`

Supporting this requires the ability to exclude fragment from type matching (or even the whole query).

safeql.configs.connections({
  overrides: {
    types: {
      array: 'ListSqlToken',
      date: 'DateSqlToken',
      json: 'JsonSqlToken',
      jsonb: 'JsonBinarySqlToken',
      timestamp: 'TimestampSqlToken',
+      // obvious not, but this appears to be not used anywhere, and I still need to provide a valid type
+      timestamptz: 'SqlFragmentToken',
      uuid: '`${string}-${string}-${string}-${string}-${string}`',
    },
  },

I've tried working around this by assigning a random type, but this causes queries to fail, e.g.

Invalid Query: column "location" is of type geometry but expression is of type timestamp with time zone

Note that there might be multiple that need an escape hatch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions