Member Junction
    Preparing search index...

    SQL Server dialect implementation. Uses [bracket] quoting, TOP for pagination, BIT for booleans, T-SQL functions.

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get AllowsOrderByInCTE(): boolean

      Whether the platform allows ORDER BY inside CTE definitions without TOP, OFFSET, or FOR XML. SQL Server: false (ORDER BY in CTEs is illegal without TOP/OFFSET/FOR XML) PostgreSQL: true (ORDER BY in CTEs is always legal)

      Returns boolean

    • get BinaryTypeNames(): readonly string[]

      SQL type names this dialect uses for binary blob columns (image, bytea, varbinary).

      Returns readonly string[]

    • get DefaultPagingOrderBy(): string

      Default ORDER BY expression for paging when no user-specified ORDER BY exists. SQL Server: '(SELECT NULL)', PostgreSQL: '1'

      Returns string

    • get FixedWidthStringTypeNames(): readonly string[]

      Subset of StringTypeNames that represents fixed-width / space-padded character types. SQL Server char/nchar and PostgreSQL char/bpchar/character (without varying) all right-pad stored values with spaces up to the declared length and return that padding in result sets. Variable-width types (varchar, nvarchar, text, etc.) do not.

      Used by BaseEntity to rtrim padding on load so dirty-checks and downstream consumers see the logical value, not the storage form.

      Returns readonly string[]

    • get IntegerTypeNames(): readonly string[]

      SQL type names this dialect uses for integer columns (int, bigint, smallint, …).

      Returns readonly string[]

    • get MaxInRowSizeBytes(): number

      SQL Server enforces a hard ~8060-byte in-row row size; only variable-length values go off-row.

      Returns number

    • get NetworkTypeNames(): readonly string[]

      SQL type names this dialect uses for network address columns (inet, cidr, …).

      Returns readonly string[]

    • get NullLiteral(): string

      Returns the dialect's literal representation of NULL as it would appear in generated SQL (e.g. as the result of a default-value formatter). Both SQL Server and PostgreSQL use the bare keyword NULL, but a future dialect could differ — codegen comparisons should route through this rather than hard-coding the string.

      Returns string

    • get ParserDialect(): string

      Returns the dialect name used by node-sql-parser for AST parsing. SQL Server: 'TransactSQL', PostgreSQL: 'PostgresQL', etc.

      Returns string

    • get StringTypeNames(): readonly string[]

      SQL type names this dialect uses for variable-length character / text columns.

      Returns readonly string[]

    Methods

    • Wraps a single DML statement so the number of rows it affected comes back as a one-row, one-column result set — the portable way to read an affected-row count without relying on a driver-specific rowsAffected field.

      SQL Server appends SELECT @@ROWCOUNT. PostgreSQL has no @@ROWCOUNT at all, so it wraps the statement in a data-modifying CTE and counts the RETURNING rows.

      dmlStatement must be exactly one INSERT/UPDATE/DELETE and carry no trailing semicolon: the PostgreSQL form is a CTE, which cannot wrap a statement batch.

      Parameters

      • dmlStatement: string
      • alias: string

      Returns string

    • Wraps a list of statements in ONE all-or-nothing transaction batch for this platform, ready to run as a single ExecuteSQL(script) call. Owns the platform-specific session/transaction setup so callers don't sniff PlatformKey themselves:

      • SQL Server: SET QUOTED_IDENTIFIER ON / SET ANSI_NULLS ON (required for UPDATE/DELETE against tables with filtered / computed-column indexes or indexed views — Msg 1934 otherwise)
        • SET XACT_ABORT ON (any failure rolls the whole batch back) + BEGIN/COMMIT TRANSACTION.
      • PostgreSQL: plain BEGIN … COMMIT — no session pragmas (QUOTED_IDENTIFIER/ANSI_NULLS are SQL-Server concepts) and PostgreSQL already aborts the whole transaction on any error.

      Returns an empty string for an empty statement list (nothing to run).

      Parameters

      • statements: string[]

        individual SQL statements (each WITHOUT a trailing ;)

      Returns string

    • Returns the SQL type token for a boolean parameter in a stored-procedure / function signature. Used by codegen when emitting tolerant-SP _Clear companion parameters and other boolean-typed params.

      SQL Server: bit (BIT type, 0/1) PostgreSQL: boolean (BOOLEAN type, TRUE/FALSE)

      Hardcoding bit everywhere worked on SQL Server but produced sprocs that PG rejected as operator does not exist: boolean = integer when the generated CASE compared a bit-declared parameter with = 1.

      Returns string

    • Returns a CAST to a bounded-width string type. Used when the result needs to be comparable against an indexed column (SQL Server cannot compare/index NVARCHAR(MAX)) or against a fixed-width text column such as MJ's RecordID (NVARCHAR(450) on SQL Server).

      Implemented by composing ResolveAbstractType({ type: 'string', maxLength }), which dialects already supply — SQL Server emits NVARCHAR(N) and PostgreSQL emits VARCHAR(N). Defaults to MJ's standard 450-char width to match the cap on indexable string columns in SQL Server.

      Parameters

      • expr: string
      • maxLength: number = 450

      Returns string

    • SQL Server supports COALESCE as an ANSI-standard alternative to its native ISNULL. The two differ subtly in return-type inference and argument arity (COALESCE is n-ary; ISNULL is two-arg only). Use this helper when codegen needs the n-ary form or when caller intent is ANSI-portable rather than T-SQL-native.

      Parameters

      • expr: string
      • fallback: string

      Returns string

    • Returns description metadata SQL for a column. SQL Server: EXEC sp_addextendedproperty with

      Parameters

      • schema: string
      • table: string
      • column: string
      • comment: string

      Returns string

      = 'COLUMN' PostgreSQL: COMMENT ON COLUMN schema."table"."column" IS '...';

      This extends CommentOnObject to support the 3-part column reference that CommentOnObject doesn't handle.

    • CommentOnColumn that is safe to re-run. Default returns the standard statement (PostgreSQL COMMENT ON COLUMN already includes its terminator and is idempotent). SQL Server overrides to guard sp_addextendedproperty.

      Parameters

      • schema: string
      • table: string
      • column: string
      • comment: string

      Returns string

    • Returns a COMMENT ON statement (PostgreSQL) or sp_addextendedproperty (SQL Server).

      Parameters

      • objectType: string
      • schema: string
      • name: string
      • comment: string

      Returns string

    • CommentOnObject that is safe to re-run (no error if the description already exists). Default returns the standard statement terminated with ';' — adequate where the comment statement is inherently idempotent (PostgreSQL COMMENT ON replaces in place). SQL Server overrides to guard sp_addextendedproperty with a fn_listextendedproperty check.

      Parameters

      • objectType: string
      • schema: string
      • name: string
      • comment: string

      Returns string

    • Returns a conditional IF/ELSE block in platform-appropriate procedural SQL. SQL Server: IF (condition) BEGIN thenSQL END ELSE BEGIN elseSQL END PostgreSQL: DO $$ BEGIN IF condition THEN thenSQL; ELSE elseSQL; END IF; END $$;

      Parameters

      • condition: string

        SQL boolean condition

      • thenSQL: string

        SQL to execute when condition is true

      • OptionalelseSQL: string

        Optional SQL to execute when condition is false

      Returns string

    • A full CREATE TABLE that runs only if the table is absent, as a SINGLE statement. Default (PostgreSQL et al.): CREATE TABLE IF NOT EXISTS <fullTable> (...); SQL Server overrides with an IF OBJECT_ID(...) IS NULL guard (it has no native CREATE TABLE IF NOT EXISTS).

      Parameters

      • fullTable: string

        Already-quoted schema.table identifier

      • columnsBody: string

        The column/constraint lines that go between the parentheses

      Returns string

    • Returns a full CREATE TABLE wrapped in a "create if not exists" guard. SQL Server: IF NOT EXISTS (sys.tables check) BEGIN CREATE TABLE ... END; PostgreSQL: CREATE TABLE IF NOT EXISTS ...;

      Parameters

      • schema: string

        Schema name

      • tableName: string

        Table name

      • columnsDDL: string

        The column definitions (everything between the parentheses)

      Returns string

    • Returns a date/time arithmetic expression. SQL Server: DATEADD(MINUTE, 30, GETUTCDATE()) PostgreSQL: (NOW() AT TIME ZONE 'UTC') + INTERVAL '30 minutes'

      Parameters

      • unit: "MINUTE" | "HOUR" | "DAY"

        Time unit

      • amount: number

        Number of units to add (can be negative)

      • baseExpr: string

        Base timestamp expression (e.g., from CurrentTimestampUTC())

      Returns string

    • Returns the empty-GUID sentinel literal (00000000-0000-0000-0000-000000000000) formatted for use in a CASE-comparison expression. The base class returns the literal as a plain quoted string — SQL Server's implicit conversion accepts that directly. Dialects with strict typing (PostgreSQL) override to add the explicit cast their grammar requires.

      Returns string

    • SQL Server-specific Flyway escape. Interleaves a CAST(N'' AS NVARCHAR(MAX)) between the split halves so the running T-SQL concat chain inherits NVARCHAR(MAX) precedence. Without the cast, N'a' + N'b' produces NVARCHAR(a+b) capped at NVARCHAR(4000) and silently truncates anything past 4,000 characters.

      Parameters

      • sql: string

      Returns string

    • Minimum in-row byte footprint of a column. Off-row-capable variable-length / LOB types (incl. (N)VARCHAR(MAX)) contribute only a 24-byte in-row pointer; fixed-length types contribute their full size. Unknown types are treated as off-row pointers (conservative).

      Parameters

      • rawSqlType: string

      Returns number

    • SQL Server FK-graph query for cascade planning — reads the sys.foreign_keys catalog. Returns one row per FK column with childNullable (from sys.columns.is_nullable) and colCount (columns in the constraint, for composite exclusion). Both parent + child are filtered to schema. Schema is embedded as a literal (no bind params) so it runs via ExecuteSQL(sql).

      Parameters

      • schema: string

      Returns string

    • Returns DDL to create a full-text index. SQL Server: FULLTEXT CATALOG + FULLTEXT INDEX PostgreSQL: tsvector column + GIN index

      Parameters

      • table: string
      • columns: string[]
      • Optionalcatalog: string

      Returns string

    • Returns a GRANT statement for the platform.

      Parameters

      • permission: string
      • _objectType: string
      • schema: string
      • object: string
      • role: string

      Returns string

    • Returns an IIF/CASE equivalent expression. SQL Server: IIF(condition, trueVal, falseVal) PostgreSQL: CASE WHEN condition THEN trueVal ELSE falseVal END

      Parameters

      • condition: string
      • trueVal: string
      • falseVal: string

      Returns string

    • Returns true if the given error represents an infrastructure-level connection failure (timeout, refused, pool closed, etc.) as opposed to a query-level error (bad SQL, constraint violation).

      Each dialect implements this using its driver's structured error types:

      • SQL Server (mssql): error.name === 'ConnectionError'
      • PostgreSQL (pg): Node.js network error codes on plain Error

      Used by GenericDatabaseProvider to re-throw connection errors from RunView/RunQuery instead of swallowing them into { Success: false }.

      Parameters

      • e: unknown

      Returns boolean

    • SQL Server has both ISNULL (T-SQL native, two-arg only) and COALESCE (ANSI, n-ary). For two-argument null-coalescing we emit the native ISNULL form so generated SPs match the conventional T-SQL idiom and the data-type-of-first-argument semantics callers may already rely on.

      Parameters

      • expr: string
      • fallback: string

      Returns string

    • Returns true if value is the dialect's representation of a NULL literal in generated SQL. Comparison is case-insensitive after trimming whitespace. Subclasses may override if a dialect uses a non-keyword form (none currently do).

      Parameters

      • value: string

      Returns boolean

    • Wraps an expression in the dialect's lowercase function — used for case-insensitive comparison when authoring filters that must work on both SS (default case-insensitive collation) and PG (case-sensitive).

      Both SQL Server and PostgreSQL implement LOWER() per the ANSI SQL standard, so the default returns LOWER(${expr}). A subclass would override only for an exotic dialect (e.g. one that exposes lc() or needs a CAST first).

      Use this instead of hardcoding LOWER(...) in callers — keeps the dialect-aware SQL surface in one place per the SQLDialect contract.

      Parameters

      • expr: string

      Returns string

    • Convenience: maps a SQL Server type to a full type string.

      Parameters

      • sqlServerType: string
      • Optionallength: number
      • Optionalprecision: number
      • Optionalscale: number

      Returns string

    • Returns the default-value clause appended to a parameter declaration. SQL Server: = NULL (or = 0, etc.), PostgreSQL: DEFAULT NULL. value should be a SQL literal already formatted by the caller (e.g. the dialect's NullLiteral, a quoted string, a numeric literal).

      Parameters

      • value: string

      Returns string

    • Returns the parameter-reference syntax used by this dialect's stored-procedure / function bodies. SQL Server: @MyName, PostgreSQL functions: p_my_name. Codegen should call this rather than hard-coding '@' + name.

      Parameters

      • name: string

      Returns string

    • SQL Server identifiers are case-insensitive by default, so a bare alias preserves the requested casing when echoed in result-set column metadata. Bracketed quoting would also work but is unnecessary.

      Parameters

      • aliasName: string

      Returns string

    • Quotes a value as a SQL string literal. Both SQL Server and PostgreSQL use single quotes with '' doubling to escape internal apostrophes — this is concrete in the base class so callers don't reinvent the value.replace(/'/g, "''") pattern. Subclasses may override if a future dialect needs a different escape rule.

      Parameters

      • value: string

      Returns string

    • Returns a non-fatal signal/notice statement detectable in CLI output. Used for signaling conditions (e.g., "lock held") without aborting the script. SQL Server: RAISERROR('message', 16, 1) — appears in sqlcmd stdout PostgreSQL: RAISE NOTICE 'message' — appears in psql stderr

      Note: For PostgreSQL, this must be used inside a ConditionalBlock (DO $$ context).

      Parameters

      • message: string

        Signal message to emit (used for detection in CLI output)

      Returns string

    • Splits an oversized SQL batch into individual statements on ;+EOL boundaries so a caller (e.g. the RSU migration executor) can re-group them into smaller chunks that each fit under a client request timeout.

      Base implementation = the naive split(/;\s*\n/g) semantics: split on a ; followed by optional inline whitespace and a newline, trim each fragment, drop empties, and ensure each returned statement ends with ;. This is correct for SQL Server (no dollar-quoted blocks).

      PostgreSQL overrides this with a dollar-quote-aware split that never tears apart DO $$ … $$ / $tag$ … $tag$ blocks whose bodies legitimately contain ;+newline.

      Parameters

      • batch: string

      Returns string[]