sqlStr (utils/sql.ts)

hivemind · src/utils/sql.ts · typescript · Apache-2.0
database

* SQL escaping utilities for Deeplake SQL API. The Deeplake HTTP query endpoint does not support parameterized queries, so we must escape values carefully before interpolation. / * Escape a string value for use inside a SQL single-quoted literal.

// Source: https://github.com/activeloopai/hivemind | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * SQL escaping utilities for Deeplake SQL API.
 *
 * The Deeplake HTTP query endpoint does not support parameterized queries,
 * so we must escape values carefully before interpolation.
 */

/**
 * Escape a string value for use inside a SQL single-quoted literal.
 * Handles: single quotes, backslashes, NUL bytes, and control characters.
 */
export function sqlStr(value: string): string {
  return value
    .replace(/\\/g, "\\\\")
    .replace(/'/g, "''")
    .replace(/\0/g, "")
    .replace(/[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
}

/**
 * Escape a string for use inside a SQL

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key