refactor(web): start Go ABI rewrite of plugins/web (W-G0)

Archive the Rust web plugin and add a Go c-shared skeleton with ABI v2
bridge, build script, design doc/ADR, and smoke test so multi-language
plugins and full web parity can proceed wave by wave.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-10 14:47:43 +08:00
1 parent fb6254e501
commit ca40c698a2
42 files changed
+955 -3

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
//! Driver URL schemes for `# db` / `# cache` / `# storage` (design ext-web-drivers).
/// Which SQL backend a `# db` URL selects.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DbKind {
Sqlite,
Postgres,
}
pub fn db_kind(url: &str) -> DbKind {
let u = url.trim().to_ascii_lowercase();
if u.starts_with("postgres://") || u.starts_with("postgresql://") {
DbKind::Postgres
} else {
DbKind::Sqlite
}
}
/// Rewrite SQL written with `?` placeholders into Postgres `$1,$2,…` form.
pub fn rewrite_placeholders_pg(sql: &str) -> String {
let mut out = String::with_capacity(sql.len() + 8);
let mut n = 0usize;
let mut chars = sql.chars().peekable();
while let Some(c) = chars.next() {
if c == '?' {
n += 1;
out.push('$');
out.push_str(&n.to_string());
} else {
out.push(c);
}
}
out
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn kind_from_url() {
assert_eq!(db_kind("sqlite:a.db"), DbKind::Sqlite);
assert_eq!(db_kind("postgres://u:p@h/db"), DbKind::Postgres);
assert_eq!(db_kind("postgresql://localhost/x"), DbKind::Postgres);
}
#[test]
fn rewrite_qmark() {
assert_eq!(
rewrite_placeholders_pg("SELECT * FROM t WHERE a = ? AND b IN (?, ?)"),
"SELECT * FROM t WHERE a = $1 AND b IN ($2, $3)"
);
}
}