Uploaded image for project: 'MariaDB Connector/node.js'
  1. MariaDB Connector/node.js
  2. CONJS-346

Add RowsWithMeta<T> and WithMeta<T> helper types for query result metadata

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • None
    • 3.5.3
    • typescript
    • None

    Description

      Users writing typed query() / execute() calls currently have to hand-author the row + FieldInfo[] shape every time, either as T[] & ( meta: FieldInfo[]) (default mode) or as [T, FieldInfo[]] (when metaAsArray: true).
      The intersection with property pattern is unintuitive to discover from the existing FieldInfo export alone, and the tuple shape is easy to get subtly wrong.

      Two helper types are added to types/share.d.ts (and the matching .d.cts) so users can express the intended shape directly:

      RowsWithMeta<T>: T[] & ( meta: FieldInfo[] ), default shape, rows with the non-enumerable meta attached.
      WithMeta<T>: [T, FieldInfo[]], with an identity branch when T is already a [any, FieldInfo[]] tuple so the legacy hand-rolled pattern keeps compiling.

      Example:

      const rows = await conn.query<RowsWithMeta<MyRow>>('SELECT ...');
      rows.meta;   // FieldInfo[]
      

      or when option `metaAsArray: true` is set :

      const [rows, meta] = await conn.query<WithMeta<MyRow[]>>('SELECT ...');
      const [res,  meta] = await conn.query<WithMeta<UpsertResult>>('UPDATE ...');
      

      No runtime changes, types-only ergonomics.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            diego dupin Diego Dupin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.