Member Junction
    Preparing search index...

    Class BaseSqlExternalDataSourceDriver<TConnection>Abstract

    Intermediate base for the relational (SQL) external data source drivers (SQL Server, PostgreSQL, MySQL, Oracle, Snowflake). Holds the logic that is genuinely identical across dialects — identifier qualification, object-type mapping, composite-key-aware FK grouping, and the SELECT skeleton — so each concrete driver only supplies the bits that actually differ per dialect:

    • quoteIdent — identifier quoting (brackets / backticks / double-quotes)
    • orderAndPageClause — the ORDER BY + paging suffix (LIMIT/OFFSET vs OFFSET/FETCH vs TOP)
    • selectTopClause — optional leading row-cap clause (T-SQL TOP (n)); default none

    Non-SQL drivers (e.g. MongoDB) extend BaseExternalDataSourceDriver directly instead.

    Type Parameters

    • TConnection = unknown

      the concrete connection/pool type the driver manages.

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Secure-transport gate for SQL-style drivers. Refuses to connect to a NON-LOCAL host over an unencrypted connection unless the caller explicitly opted in via allowInsecureTransport. Only explicit loopback literals (localhost / *.localhost / 127.0.0.0/8 / ::1) are treated as local. It fails closed: an empty or unparseable host is NOT assumed local — that would be a plaintext-leak hole (an unset host can still resolve to a remote default), so it is refused unless TLS or the explicit opt-out is set. Detection is name-based (no DNS resolution), which is a deliberate trade-off: a name that resolves to loopback but isn't a recognized literal is refused rather than silently allowed. Drivers whose transport is always encrypted (e.g. Snowflake HTTPS) don't call this.

      Parameters

      • opts: {
            allowInsecure: boolean;
            dataSourceName: string;
            host: string;
            tlsEnabled: boolean;
        }

      Returns void

    • Build the COUNT(*) SQL for a paginated view — honoring BOTH the caller's filter AND the structured incrementalSince bound via effectiveWhere, so totalRowCount is consistent with the rows the matching SELECT returns. Centralized here (rather than each driver hand-rolling WHERE ${params.filter}) so a driver can't forget the incremental bound. The cnt alias reads back per-dialect case (Oracle / Snowflake uppercase it to CNT).

      Parameters

      Returns string

    • Build a quoted, parameter-bound WHERE clause for a (possibly composite) primary key. Each key identifier is quoted via quoteIdent (so mixed-case / reserved-word PK columns work on case-sensitive dialects), and each value is returned separately for binding — never interpolated. placeholder(i) supplies the dialect's bind token for the i-th value ($1 / ? / :1 / @pk0). Returns the clause and the values in bind order.

      Parameters

      Returns { clause: string; values: (string | number | boolean | Date)[] }

    • Format the incremental bound value as a dialect SQL literal. Default: a plain single-quoted string — SQL Server / PostgreSQL / Snowflake implicitly parse an ISO-8601 timestamp string, so no wrapping is needed. Dialects whose default parser rejects the ISO T/Z form override this (e.g. the Oracle driver wraps an ISO timestamp in TO_TIMESTAMP with a matching format mask).

      Parameters

      • value: string

      Returns string

    • Evict (and close) the cached connection/pool for a data source so the next operation re-resolves its credential and reconnects. Called by withConnectionRetry on an auth failure. Implementations must be safe to call when nothing is cached for the id.

      expectedIdentity (when provided) is the exact cached handle the caller observed failing — from peekConnection. Implementations MUST only evict if the currently-cached handle is still that same identity; otherwise a concurrent request already replaced the pool with a fresh, healthy one and evicting it would cause needless reconnect churn (the H1 identity race). When expectedIdentity is undefined (explicit cache-clear, or a cold failure), evict unconditionally.

      Parameters

      • dataSourceId: string
      • OptionalexpectedIdentity: unknown

      Returns Promise<void>

    • Does this error look like an authentication/credential failure (vs. a query or network error)? Drives withConnectionRetry's decision to re-resolve the credential + retry once.

      Prefers structured vendor error codes (SQLSTATE / driver error numbers) over message-text matching — codes are locale-independent and don't false-positive on, say, a table named password_resets or an object-level "permission denied" that isn't a credential failure. The message heuristic remains a fallback for drivers/paths that don't surface a code, but the two most false-positive-prone substrings ('password', 'permission denied') were dropped in favor of the codes + more specific phrases. Drivers may override for additional vendor-specific codes.

      Parameters

      • e: unknown

      Returns boolean

    • Normalize dialect-specific syntax the read-only parser can't handle, for STRUCTURE analysis ONLY — the original SQL (with its real placeholders) is still what executes. Default: no-op. Drivers whose native syntax isn't accepted by their sqlDialectKey grammar override this: e.g. the ANSI/PostgreSQL grammar used for MySQL/Snowflake can't parse ? positional placeholders, so those drivers neutralize them here — otherwise a legitimate parameterized read is refused as unparseable. A normalization must NEVER turn a write into a read (only value/identifier-level substitutions).

      Parameters

      • sql: string

      Returns string

    • Normalize a raw remote value into an MJ-safe primitive so it round-trips losslessly and matches the type CodeGen assigns the field. Native DB drivers return values that don't survive the JS/JSON boundary: high-precision numbers as lossy numbers, JSON/complex columns as JS objects, MongoDB bson wrappers as objects. This converts:

      • BigInt → decimal string (never a lossy Number)
      • MongoDB bson Long/Decimal128 → their exact string; ObjectId → hex string; Binary → Buffer; other bson scalars → their JS value
      • plain object / array → JSON string (matches the nvarchar(MAX) CodeGen maps json/variant/nested to)
      • everything else (string/number/boolean/Date/Buffer/null) passes through unchanged. Drivers additionally configure their SDK to return large numeric COLUMNS as strings (this catches the residual cases the SDK still hands back as objects/BigInt).

      Parameters

      • v: unknown

      Returns unknown

    • Strip credentials from any connection-string-like scheme://user:pass@host embedded in a message. Driver SDKs (notably MongoDB) echo the connection URI in their errors; when a caller supplied a URI with inline credentials (e.g. mongodb://user:pass@host) those secrets would otherwise leak into logs and API error responses. Redacts the entire userinfo portion, leaving the host intact.

      Parameters

      • message: string

      Returns string

    • Re-screen a caller-supplied WHERE / ORDER-BY fragment at the driver boundary (defense in depth) before it is interpolated into a SELECT — the engine does not rely on an upstream caller having screened it. Fail-closed; see assertReadOnlyClause.

      Parameters

      • clause: string
      • kind: "where" | "orderby"

      Returns void

    • Enforce the read-only contract on a native-query string before it executes. Concrete SQL drivers MUST call this at the top of RunNativeQuery — EDS is read-only, but rendered Query SQL runs verbatim on a read/write connection and is not covered by the provider-layer Save/Delete backstop. Fail-closed: throws on stacked statements, unparseable SQL, or any write/DDL. See assertReadOnlyNativeQuery.

      Parameters

      • sql: string

      Returns void