Centralize per-database logic behind a single SqlDialect abstraction
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with src/webserver/database/mod.rs and the listed match sites in sql.rs, parameter_extraction.rs, connect.rs, execute_queries.rs, csv_import.rs, and filesystem.rs; read the existing dialect and placeholder tests in src/webserver/database/sql.rs. The issue proposes a broad, incremental refactor, so first map which per-database behaviors each site owns. Done means those behaviors are centralized with exhaustive handling for every supported database, and the existing per-dialect tests still pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Introduce a SqlDialect abstraction to make per-database logic a single source of truth
Per-database knowledge is currently scattered across many files and keyed on two parallel enums that nothing forces to agree: SupportedDatabase (8 variants: Sqlite, Duckdb, Oracle, Postgres, MySql, Mssql, Snowflake, Generic) and sqlx's AnyKind (5 variants). Because the dialect-specific data is spread over ~6 independent match sites, several keyed on the wrong enum, the compiler cannot enforce completeness: each site silently falls through to a _ default. Adding or fixing a dialect today means hunting down every site and hoping none was missed, and a missed arm is a silent correctness/data bug, not a compile error.
Proof: the references are real and scattered
$ grep -rcn -E "SupportedDatabase::(Sqlite|Postgres|MySql|Mssql|Duckdb|Oracle|Snowflake|Generic)" src | grep -v ':0' ; echo "total:" ; grep -rn -E "SupportedDatabase::(Sqlite|Postgres|MySql|Mssql|Duckdb|Oracle|Snowflake|Generic)" src | wc -l
src/webserver/database/sql.rs:37
src/webserver/database/sql/parameter_extraction.rs:9
src/filesystem.rs:3
total: 49
$ grep -rn -E "AnyKind::" src | wc -l
24
49 per-variant SupportedDatabase references (37 in sql.rs alone) plus 24 AnyKind references, all to be kept consistent by hand.
The scattered sites
dialect_for_dbreturns the sqlparser dialect via an 8-arm match: sql.rs#L293-L304- Placeholder style keyed on
AnyKind(only 5 entries), with a silent fallback to a temp prefix when a kind is absent: parameter_extraction.rs#L25-L46 - Placeholder cast type keyed on
SupportedDatabase(different enum, with a_ =>default): parameter_extraction.rs#L96-L115 - Default pool size per kind: connect.rs#L83-L94
- Trace-context SQL inlined in the execution path: execute_queries.rs#L505-L514
- CSV import reaching into sqlx's private
AnyConnectionKindto special-case the PostgresCOPYpath: csv_import.rs#L172-L177 - DB-filesystem
CREATE TABLEper dialect: filesystem.rs#L265-L280 - Name detection in
from_dbms_name, plus its inverse mapping duplicated inside the tests: sql.rs#L786-L792
The enum mismatch directly produces fragile fallthroughs that only exist because the key type is wrong:
_ => Self::Genericinfrom_dbms_name_ => run_csv_import_insert(any non-Postgres connection)unreachable!(...)when a kind is missing fromDB_PLACEHOLDERS, and the silent temp-prefix fallback for an unlisted kind (parameter_extraction.rs#L58-L60)
Proposed change
Introduce a single trait SqlDialect (or a method-rich impl on SupportedDatabase) that centralizes everything per-DB:
- placeholder style and placeholder cast type
- sqlparser
Dialect - otel
db.system.name - default pool size
- capability flags: native JSON,
COPY FROM STDIN, trace propagation, rollback statement,::cast support, MSSQL concat rewriting
Crucially, key the placeholder data on SupportedDatabase and make DB_PLACEHOLDERS (and the other tables) an exhaustive match, so the compiler forces every dialect to be handled and the unreachable!/_ => Odbc/_ => Generic fallthroughs disappear. Adding or fixing a dialect then becomes "implement one trait / add the arm the compiler demands" instead of editing ~6 scattered sites that nothing forces to agree.
Risks and mitigations
- Large but mechanical refactor. Mitigate by leaning on the existing dialect/placeholder tests in
sql.rs(theALL_DIALECTStable drives many of them) which already pin per-dialect behavior. - Land it incrementally, one capability at a time, so each step stays reviewable and bisectable.
Expected win
- Single source of truth for per-DB behavior.
- Compiler-enforced dialect completeness instead of hand-synced matches across two enums.
- Removes the silent
_ => Odbc/_ => Genericfallthroughs that can quietly mishandle (or corrupt data for) an unlisted dialect.
This refines the "split sql.rs by responsibility" suggestion in #1249: a SqlDialect abstraction is the natural seam to split along.
- Ngôn ngữ chính
- Rust
- Star
- 2.6k
- Fork
- 175
- Merge trung bình
- 14 giờ 16 phút
- Pull request đã merge (30 ngày)
- 43
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sqlpage/SQLPage
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
sqlpage/SQLPage#1218 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
There is no convenient way to reproduce issuesCó thể đã có người làm @81reap đã nhận 26 ngày trước. Đang mởenhancement
sqlpage/SQLPage#1566 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Confusing sort interfaceCó thể đã có người làm @lovasoa đã nhận 74 ngày trước. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
sqlpage/SQLPage#1442 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Mutation Testing Results :: Dead Code + Missing TestsCó thể làm lại được @81reap đã nhận 61 ngày trước và không có pull request nào đang mở. Đang mở
sqlpage/SQLPage#1396 · 5 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của sqlpage/SQLPage
Issue tương tự
-
CI/CD ignore-for-release
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
eclipse-ankaios/ankaios#844 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
std: `SliceIndex<str>` missing for `std::ops` ranges, so generic `R: SliceIndex<str>` bounds failĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
symposium-dev/symposium#530 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày