Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:4paradigm OpenMLDB Database Driver Implementation

From Leeroopedia
Knowledge Sources
Domains SDK, Database
Last Updated 2026-10-12 12:00 GMT

Overview

A driver implementation pattern that adapts a database's wire protocol (HTTP/JSON) to a standard SQL driver interface, enabling seamless integration with language-native database APIs.

Description

Database driver implementation bridges a database's native protocol with a language's standard database interface. In OpenMLDB, the Go SDK driver implements Go's database/sql/driver interfaces by translating standard SQL operations into HTTP POST requests to the OpenMLDB API server. The driver handles DSN parsing, connection management, query mode selection (offline/online), parameter serialization, and response deserialization. This allows Go applications to use OpenMLDB through the familiar database/sql API without knowing the underlying HTTP protocol.

The key problem solved is API compatibility: applications written for standard SQL databases (PostgreSQL, MySQL) can switch to OpenMLDB by changing only the driver import and DSN, without rewriting query logic.

Usage

Use this principle when providing SDK access to a database that uses a non-standard wire protocol. Implement the standard driver interfaces of the target language to enable drop-in compatibility with existing database clients.

Theoretical Basis

The driver pattern follows the adapter pattern from software design:

App→database/sql APIDriver→HTTP POSTOpenMLDB API Server

The driver implements these interfaces:

// Abstract interface description (from database/sql/driver)
type Driver interface {
    Open(name string) (Conn, error)
}

type Conn interface {
    QueryContext(ctx, query, args) (Rows, error)
    ExecContext(ctx, query, args) (Result, error)
    Ping(ctx) error
    Close() error
}

type Rows interface {
    Columns() []string
    Next(dest []Value) error
    Close() error
}

The driver translates each call:

  • Open(dsn) → parse DSN, create conn struct
  • QueryContext → HTTP POST with SQL and parameters as JSON
  • Next() → iterate pre-parsed JSON response rows
  • Ping → execute SELECT 1 via HTTP

Practical Guide

  • Use side-effect import (_ "github.com/4paradigm/openmldb/go") to register the driver
  • The DSN format is openmldb://host:port/db?mode=offsync|offasync|online
  • mode=online is for real-time feature serving; mode=offsync is for synchronous offline jobs
  • The driver does not support Prepare() or Begin() — use QueryContext directly

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment