feat(db): add IBM Db2 LUW provider (#786) - #787
Open
nycjay wants to merge 2 commits into
Open
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
added 2 commits
September 11, 2026 11:01
Connect to Db2 LUW over DRDA with the native ibm_db driver. The provider extends SQLBaseProvider and overrides only prepareQuery(): Db2's SQL is Oracle-shaped (double-quoted identifiers, FETCH FIRST / OFFSET ... FETCH NEXT paging), so identifier escaping is inherited unchanged. Schema reads the SYSCAT.* catalog views scoped to CURRENT SCHEMA. Per-table maintenance maps analyze to RUNSTATS and optimize to REORG through SYSPROC.ADMIN_CMD; Db2 has no whole-database form, so there is no global maintenance card. Bound ? parameters are forwarded to the driver so inline row edit works (UPDATE ... WHERE pk); verified end-to-end against Db2 v11.5.9.0. Capabilities are conservative and honest: supportsExplain false (Db2 EXPLAIN populates explain tables rather than returning a single-statement plan, same as MSSQL libredb#126), supportsTransactions false (no held-session transaction wired, so the toolbar and SANDBOX stay hidden), and monitoring panels return neutral empties instead of fabricated zeros. All documented as intentional follow-ups. Includes the provider triad (db2.ts, docs/providers/db2.md, and the integration test at 100% line coverage), the registration surfaces, a db2 service in database-compose.yml, and the external-engine count copy. Closes libredb#786
…#786) Answers the review ask to check the admin/monitoring capabilities. Every MON_GET_* / SYSIBMADM.* read is permission-gated and wrapped so a restricted account degrades to an empty panel instead of an error; a monitoring-authorized account (verified on Db2 v11.5.9.0) gets real figures. - getTableStats: real per-table rows from SYSCAT.TABLES — row count (CARD) and the RUNSTATS timestamp (STATS_TIME -> lastAnalyze), so the age of the count is visible. CARD = -1 / STATS_TIME NULL maps to "no stats" (0 rows, no lastAnalyze), never a literal -1. Size deferred (per-object only). - getActiveSessions: live connections from MON_GET_CONNECTION. - getSlowQueries: costliest cached statements from MON_GET_PKG_CACHE_STMT, filtered to rows that actually carry timings (NUM_EXEC_WITH_METRICS > 0). When the database's mon_req_metrics is off there are none, so the panel shows a Db2-specific empty state naming the exact enablement command rather than the Postgres pg_stat_statements wording (slowQueriesEmptyState label). - getStorageStats: per-tablespace sizing from MON_GET_TABLESPACE. - getIndexStats: per-index rows from SYSCAT.INDEXES/INDEXCOLUSE with scan counts LEFT JOINed (RTRIM) from MON_GET_INDEX. - getPerformanceMetrics/getHealth: cache hit ratio from SYSIBMADM.BP_HITRATIO (works regardless of mon_obj_metrics, unlike MON_GET_BUFFERPOOL) and deadlocks from MON_GET_DATABASE. - getOverview: uptime (computed IN the database to avoid a timezone-driven negative), database size (+ databaseSizeBytes so fleet-health totals it), table/index counts, active connections, and maxConnections (maxappls). Hardening: - validate() rejects ';' in host/database/user/password: the DRDA attribute list has no escaping for its delimiter, so a value with ';' misparses (a password fails auth) or injects an attribute (PWD=x;SECURITY=NONE connected in testing). Pasted connection strings remain the user's own responsibility. - prepareQuery: pin the trailing-semicolon and trailing-line-comment cases (the clause splices before the trivia, never inside a comment). Tests updated to 100% line coverage of db2.ts; docs/providers/db2.md rewritten to describe each surface, its source, and its honest limits (per-object size, slow-query timings needing mon_req_metrics, the data/index Storage Breakdown that ADMIN_GET_TAB_INFO makes too slow to fill).
nycjay
force-pushed
the
feat/786-db2-luw-provider
branch
from
September 11, 2026 15:16
af19bea to
173c834
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds IBM Db2 LUW as a database provider (type-id db2), over the DRDA protocol with the native ibm_db driver. It extends SQLBaseProvider and overrides only prepareQuery(), because Db2's SQL is Oracle-shaped (double-quoted identifiers, FETCH FIRST / OFFSET ... FETCH NEXT paging).
Type of Change
Related Issue
Closes #786
Changes Made
Deliberate follow-ups, not gaps: supportsExplain: false (Db2 EXPLAIN populates explain tables rather than returning a single-statement plan, same as MSSQL #126), supportsTransactions: false (no held-session transaction wired, so the toolbar and SANDBOX stay hidden), monitoring panels return neutral empties instead of fabricated zeros, and columnTypes is omitted because the high-level query() exposes no declared type.
Testing
Verified end-to-end against a live Db2 v11.5.9.0 server, driving the app with Playwright and the API: connect and schema tree (columns, PK/nullable, FKs, indexes, untrimmed names); paging (FETCH FIRST, then OFFSET ... FETCH NEXT, an already-bounded query left alone); CRUD with read-your-writes; value fidelity (BIGINT → lossless string, BLOB → Buffer, CLOB/DECFLOAT/XML, CHAR(n) space-padded as expected); error paths (SQL0204N, SQL0104N throw rather than returning zero rows); per-table RUNSTATS/REORG plus rejection of a global or unsupported op; capability-gated UI (no Explain button or tab, no transaction toolbar/SANDBOX, Create Table present, inline-edit present); and an inline row edit persisting through UPDATE ... WHERE pk. ibm_db loads under both Bun and Node.
Two commands I could not run locally (per the "CI is the merge gate" note in CONTRIBUTING):
Test Environment
Screenshots (if applicable)
Checklist
bun run test:coverageandbun run coverage:check)src/lib/db/providers/, I updated the matchingdocs/providers/documentation andtests/integration/db/tests in the same PR (provider triad)Additional Notes
This PR adds a runtime dependency (ibm_db), unlike the recent HTTP-only providers. Rationale is under Changes Made.