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

Add generic type parameter for query values in TypeScript definitions

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 3.5.1
    • typescript
    • None

    Description

      from PR : https://github.com/mariadb-corporation/mariadb-connector-nodejs/pull/334

      Previously, TypeScript generics were only available for result sets (T), not for input values:

      // Before: values typed as `any`, no type safety on inputs
      const result = await conn.query<UserRow>('SELECT * FROM users WHERE id = ?', [id]);
      

      This change adds a generic type parameter V to values on query, execute, batch, prepare, queryStream, and executeStream, enabling type safety for both inputs and outputs:

      // After: both result type T and values type V are available
      type UserRow = { id: number; email: string };
      type UserInsert = [string, Buffer, Buffer];
       
      const rows = await conn.query<UserRow[], [number]>('SELECT * FROM users WHERE id = ?', [id]);
      const stmt = await conn.prepare<UserInsert>(sql);
      await stmt.execute([email, hash, salt]); // enforces UserInsert type
      

      All generic parameters default to any, so existing code is fully backward compatible.

      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.