Skip to content

SQL Values? #17

Open
Open

Description

@riziles

How about adding this?

/**
 * Generates JS dataframe objects.
 * Supports base, polars frameworks.
 * @param {Object} tableData - Table data
 * @param {string[]} tableData.headers - headers
 * @param {any[][]} tableData.data - rows
 * @param {string[]} tableData.columnTypes - rows
 *
 */
function createSQLValues(tableData) {
  const { headers, data, columnTypes } = tableData;
  let code = '';

  /**
   * Formats a value according to its column type for R syntax
   * @param {any} value - The value to format
   * @param {number} colIndex - Column index for type lookup
   * @returns {string} Formatted value
   */
  function formatValue(value, colIndex) {
    if (value === '') {
      return 'null';
    } else if (columnTypes[colIndex] === 'string') {
      return `'${value}'`;
    } else if (columnTypes[colIndex] === 'numeric') {
      return addTrailingZeroes(value);
    } else if (columnTypes[colIndex] === 'boolean') {
      return normalizeBool(value, 'python');
    } else if (columnTypes[colIndex] === 'integer') {
      return value;
    } else {
      return `"${value}"`;
    }
  }
  code = `select * from (values\n\n`;
  data.forEach((row_j, j) => {
    const values = row_j.map((row, i) => formatValue(row, i)).join(', ');
    code += `    (${values})${j < data.length - 1 ? ',\n' : '\n'}`;
  });

  code += `) t (${headers})`;
  return code;
}

Activity

  1. atsyplenkov commented on Apr 5, 2025

    @atsyplenkov
    Owner

    Nice! Can you please prepare a PR?

  2. riziles commented on Apr 5, 2025

    @riziles
    Author

    I don't have all the VS Code extension stuff installed to test it. I just prototyped in vanilla js using StackBlitz:
    https://stackblitz.com/edit/vitejs-vite-ee1ebsyv?file=index.html

  3. atsyplenkov commented on Apr 5, 2025

    @atsyplenkov
    Owner

    No worries, I'll take a look next week

  4. self-assigned this
    on Apr 6, 2025
  5. added
    enhancement
    on Apr 6, 2025
  6. atsyplenkov commented on Sep 20, 2025

    @atsyplenkov
    Owner

    Hi @riziles. Thanks to @juarezr, we have finally implemented the SQL support. Could you please look at the development version and tell us if it works correctly or as you expected? You can access the development version from the CI artefacts or via this link.

  7. riziles commented on Sep 20, 2025

    @riziles
    Author

    Sorry, I was blocked from downloading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions