XU XUv0.16.0

#database/sql/driver

import: #database/sql/driver

counts: 8 functions, 0 methods, 7 types, 0 constants, 5 method sets

Driver snapshot RowsResult plus Conn/Stmt/Tx/Driver.

Examples · API declarations

Examples

These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.

34_standalone_postgres/main.xu

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@main

postgres #github.com/xulang-org/packages/postgres
#database/sql/driver
#context

fn verify_postgres_live() {
    println("--- Testing Native Postgres Driver Wire Protocol ---")
    dsn := "postgres://zicq:zicq@127.0.0.1:5432/xu_demo?sslmode=disable"
    $conn := postgres.open(dsn)

    // 1. Ping
    err := conn.ping()
    if err.len > 0 {
        println("   [FAIL] Ping failed: " + err)
        conn.close()
        <<
    }
    println("   [PASS] Postgres Ping succeeded.")

    // 2. Exec DDL
    r1 := conn.exec("DROP TABLE IF EXISTS xu_heroes;", []driver.NamedValue{})
    if r1.err.len > 0 {
        println("   [FAIL] Drop table error: " + r1.err)
        conn.close()
        <<
    }
    r2 := conn.exec("CREATE TABLE xu_heroes (id INTEGER PRIMARY KEY, name VARCHAR(50), power INTEGER);", []driver.NamedValue{})
    if r2.err.len > 0 {
        println("   [FAIL] Create table error: " + r2.err)
        conn.close()
        <<
    }
    println("   [PASS] Table 'xu_heroes' created.")

    // 3. Exec DML Insert
    $args1 := []driver.NamedValue{}
    args1.push(driver.NamedValue{ordinal: 1, name: "", value: 1})
    args1.push(driver.NamedValue{ordinal: 2, name: "", value: "Ironman"})
    args1.push(driver.NamedValue{ordinal: 3, name: "", value: 100})
    r3 := conn.exec("INSERT INTO xu_heroes (id, name, power) VALUES ($$1, $$2, $$3);", args1)
    if r3.err.len > 0 {
        println("   [FAIL] Insert error: " + r3.err)
        conn.close()
        <<
    }
    println("   [PASS] Hero inserted (rows=" + str(r3.rows_affected) + ").")

    // 4. Query
    $q_args := []driver.NamedValue{}
    q_args.push(driver.NamedValue{ordinal: 1, name: "", value: 1})
    rows := conn.query("SELECT id, name, power FROM xu_heroes WHERE id = $$1;", q_args)
    if rows.err.len > 0 {
        println("   [FAIL] Query error: " + rows.err)
        conn.close()
        <<
    }
    println("   [PASS] Query executed, columns count: " + str(rows.columns.len))
    $i := 0
    while i < rows.columns.len {
        println("      Col[" + str(i) + "]: " + rows.columns[i])
        i = i + 1
    }
    println("   Total cells retrieved: " + str(rows.cells.len))
    $j := 0
    while j < rows.cells.len {
        println("      Cell[" + str(j) + "]: " + rows.cells[j])
        j = j + 1
    }

    // 5. Transaction
    println("   Testing Transaction Commit...")
    $tx := conn.begin()
    $args2 := []driver.NamedValue{}
    args2.push(driver.NamedValue{ordinal: 1, name: "", value: 2})
    args2.push(driver.NamedValue{ordinal: 2, name: "", value: "Thor"})
    args2.push(driver.NamedValue{ordinal: 3, name: "", value: 200})
    tx_res := conn.exec("INSERT INTO xu_heroes (id, name, power) VALUES ($$1, $$2, $$3);", args2)
    if tx_res.err.len > 0 {
        println("   [FAIL] Tx insert error: " + tx_res.err)
    }
    tx_err := tx.commit()
    if tx_err.len > 0 {
        println("   [FAIL] Tx commit error: " + tx_err)
    } else {
        println("   [PASS] Transaction committed.")
    }

    // 6. Reset session
    ctx := context.background()
    reset_err := conn.reset_session(&ctx)
    if reset_err.len > 0 {
        println("   [FAIL] Reset session error: " + reset_err)
    } else {
        println("   [PASS] Reset session completed.")
    }

    // 7. Close
    close_err := conn.close()
    if close_err.len > 0 {
        println("   [FAIL] Close error: " + close_err)
    } else {
        println("   [PASS] Connection closed cleanly.")
    }
}

fn verify_postgres_pool() {
    println("\n--- Testing Native Postgres Connection Pool ---")
    dsn := "postgres://zicq:zicq@127.0.0.1:5432/xu_demo?sslmode=disable"
    $pool := postgres.open_pool(dsn + "", 5, 2)

    pool.ping() >>> (err) {
        println("   [FAIL] Pool ping error: " + err.msg())
        <<
    }
    println("   [PASS] Postgres Pool ping succeeded.")

    // 1. DDL
    pool.exec("DROP TABLE IF EXISTS xu_pool_users;") >>> (err) {
        println("   [FAIL] Drop table error: " + err.msg())
        <<
    }
    pool.exec("CREATE TABLE xu_pool_users (id INTEGER PRIMARY KEY, name VARCHAR(50), balance INTEGER);") >>> (err) {
        println("   [FAIL] Create table error: " + err.msg())
        <<
    }
    println("   [PASS] Pool created table xu_pool_users.")

    // 2. Concurrency / multiple inserts
    $i := 1
    while i <= 5 {
        pool.exec("INSERT INTO xu_pool_users (id, name, balance) VALUES ($$1, $$2, $$3);", i, "User_" + str(i), i * 100) >>> (err) {
            println("   [FAIL] Insert row error: " + err.msg())
            <<
        }
        i = i + 1
    }
    println("   [PASS] Concurrently inserted 5 rows across pooled connections.")

    // 3. Query
    $rows := pool.query("SELECT id, name, balance FROM xu_pool_users ORDER BY id;") >>> (err) {
        println("   [FAIL] Pool query error: " + err.msg())
        <<
    }
    $count := 0
    while rows.next() {
        vals := rows.take() >>> (err) {
            println("   [FAIL] rows.take error: " + err.msg())
            <<
        }
        uid := vals[0] as int
        uname := vals[1] as string
        ubal := vals[2] as int
        println("      Row[" + str(count) + "]: id=" + str(uid) + ", name=" + uname + ", bal=" + str(ubal))
        count = count + 1
    }
    rows.close()
    if count == 5 {
        println("   [PASS] Pool query verified 5 rows.")
    } else {
        println("   [FAIL] Row count mismatch: " + str(count))
    }

    // 4. Transaction via Pool
    $tx := pool.begin() >>> (err) {
        println("   [FAIL] Pool begin tx error: " + err.msg())
        <<
    }
    tx.exec("INSERT INTO xu_pool_users (id, name, balance) VALUES ($$1, $$2, $$3);", 6, "User_6", 600) >>> (err) {
        println("   [FAIL] Tx insert error: " + err.msg())
        <<
    }
    tx.commit() >>> (err) {
        println("   [FAIL] Tx commit error: " + err.msg())
        <<
    }
    println("   [PASS] Transaction committed via pool.")

    // 5. Cleanup & Close
    pool.exec("DROP TABLE IF EXISTS xu_pool_users;") >>> (err) {
        println("   [FAIL] Cleanup table error: " + err.msg())
        <<
    }
    pool.close() >>> (err) {
        println("   [FAIL] Pool close error: " + err.msg())
        <<
    }
    println("   [PASS] Postgres Pool closed cleanly.")
}

fn main() {
    println("=== Xu PostgreSQL Native Driver Verification ===\n")
    verify_postgres_live()
    verify_postgres_pool()
    println("\n[POSTGRES VERIFICATION 100% COMPLETED]")
}
35_standalone_mysql/main.xu

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@main

mysql #github.com/xulang-org/packages/mysql
#database/sql/driver
#context

fn verify_mysql_live() {
    println("--- Testing Native MySQL/MariaDB Driver Wire Protocol ---")
    dsn := "root:root@tcp(127.0.0.1:3306)/xu_demo?tls=false"
    $conn := mysql.open(dsn)

    // 1. Ping
    err := conn.ping()
    if err.len > 0 {
        println("   [FAIL] Ping failed: " + err)
        conn.close()
        <<
    }
    println("   [PASS] MySQL/MariaDB Ping succeeded.")

    // 2. Exec DDL
    r1 := conn.exec("DROP TABLE IF EXISTS xu_developers;", []driver.NamedValue{})
    if r1.err.len > 0 {
        println("   [FAIL] Drop table error: " + r1.err)
        conn.close()
        <<
    }
    r2 := conn.exec("CREATE TABLE xu_developers (id INT PRIMARY KEY, name VARCHAR(50), commits INT);", []driver.NamedValue{})
    if r2.err.len > 0 {
        println("   [FAIL] Create table error: " + r2.err)
        conn.close()
        <<
    }
    println("   [PASS] Table 'xu_developers' created.")

    // 3. Exec DML Insert
    $args1 := []driver.NamedValue{}
    args1.push(driver.NamedValue{ordinal: 1, name: "", value: 1})
    args1.push(driver.NamedValue{ordinal: 2, name: "", value: "Antigravity"})
    args1.push(driver.NamedValue{ordinal: 3, name: "", value: 500})
    r3 := conn.exec("INSERT INTO xu_developers (id, name, commits) VALUES (?, ?, ?);", args1)
    if r3.err.len > 0 {
        println("   [FAIL] Insert error: " + r3.err)
        conn.close()
        <<
    }
    println("   [PASS] Developer inserted (rows=" + str(r3.rows_affected) + ").")

    // 4. Query
    $q_args := []driver.NamedValue{}
    q_args.push(driver.NamedValue{ordinal: 1, name: "", value: 1})
    rows := conn.query("SELECT id, name, commits FROM xu_developers WHERE id = ?;", q_args)
    if rows.err.len > 0 {
        println("   [FAIL] Query error: " + rows.err)
        conn.close()
        <<
    }
    println("   [PASS] Query executed, columns count: " + str(rows.columns.len))
    $i := 0
    while i < rows.columns.len {
        println("      Col[" + str(i) + "]: " + rows.columns[i])
        i = i + 1
    }
    println("   Total cells retrieved: " + str(rows.cells.len))
    $j := 0
    while j < rows.cells.len {
        println("      Cell[" + str(j) + "]: " + rows.cells[j])
        j = j + 1
    }

    // 5. Transaction
    println("   Testing Transaction Commit...")
    $tx := conn.begin()
    $args2 := []driver.NamedValue{}
    args2.push(driver.NamedValue{ordinal: 1, name: "", value: 2})
    args2.push(driver.NamedValue{ordinal: 2, name: "", value: "XuArchitect"})
    args2.push(driver.NamedValue{ordinal: 3, name: "", value: 1000})
    tx_res := conn.exec("INSERT INTO xu_developers (id, name, commits) VALUES (?, ?, ?);", args2)
    if tx_res.err.len > 0 {
        println("   [FAIL] Tx insert error: " + tx_res.err)
    }
    tx_err := tx.commit()
    if tx_err.len > 0 {
        println("   [FAIL] Tx commit error: " + tx_err)
    } else {
        println("   [PASS] Transaction committed.")
    }

    // 6. Reset session
    ctx := context.background()
    reset_err := conn.reset_session(&ctx)
    if reset_err.len > 0 {
        println("   [FAIL] Reset session error: " + reset_err)
    } else {
        println("   [PASS] Reset session completed.")
    }

    // 7. Close
    close_err := conn.close()
    if close_err.len > 0 {
        println("   [FAIL] Close error: " + close_err)
    } else {
        println("   [PASS] Connection closed cleanly.")
    }
}

fn verify_mysql_pool() {
    println("\n--- Testing Native MySQL/MariaDB Connection Pool ---")
    dsn := "root:root@tcp(127.0.0.1:3306)/xu_demo?tls=false"
    $pool := mysql.open_pool(dsn + "", 5, 2)

    pool.ping() >>> (err) {
        println("   [FAIL] Pool ping error: " + err.msg())
        <<
    }
    println("   [PASS] MySQL Pool ping succeeded.")

    // 1. DDL
    pool.exec("DROP TABLE IF EXISTS xu_pool_orders;") >>> (err) {
        println("   [FAIL] Drop table error: " + err.msg())
        <<
    }
    pool.exec("CREATE TABLE xu_pool_orders (id INT PRIMARY KEY, title VARCHAR(50), amount INT);") >>> (err) {
        println("   [FAIL] Create table error: " + err.msg())
        <<
    }
    println("   [PASS] Pool created table xu_pool_orders.")

    // 2. Concurrency / multiple inserts
    $i := 1
    while i <= 5 {
        pool.exec("INSERT INTO xu_pool_orders (id, title, amount) VALUES (?, ?, ?);", i, "Order_" + str(i), i * 150) >>> (err) {
            println("   [FAIL] Insert row error: " + err.msg())
            <<
        }
        i = i + 1
    }
    println("   [PASS] Concurrently inserted 5 rows across pooled connections.")

    // 3. Query
    $rows := pool.query("SELECT id, title, amount FROM xu_pool_orders ORDER BY id;") >>> (err) {
        println("   [FAIL] Pool query error: " + err.msg())
        <<
    }
    $count := 0
    while rows.next() {
        vals := rows.take() >>> (err) {
            println("   [FAIL] rows.take error: " + err.msg())
            <<
        }
        oid := vals[0] as int
        otitle := vals[1] as string
        oamt := vals[2] as int
        println("      Row[" + str(count) + "]: id=" + str(oid) + ", title=" + otitle + ", amount=" + str(oamt))
        count = count + 1
    }
    rows.close()
    if count == 5 {
        println("   [PASS] Pool query verified 5 rows.")
    } else {
        println("   [FAIL] Row count mismatch: " + str(count))
    }

    // 4. Transaction via Pool
    $tx := pool.begin() >>> (err) {
        println("   [FAIL] Pool begin tx error: " + err.msg())
        <<
    }
    tx.exec("INSERT INTO xu_pool_orders (id, title, amount) VALUES (?, ?, ?);", 6, "Order_6", 900) >>> (err) {
        println("   [FAIL] Tx insert error: " + err.msg())
        <<
    }
    tx.commit() >>> (err) {
        println("   [FAIL] Tx commit error: " + err.msg())
        <<
    }
    println("   [PASS] Transaction committed via pool.")

    // 5. Cleanup & Close
    pool.exec("DROP TABLE IF EXISTS xu_pool_orders;") >>> (err) {
        println("   [FAIL] Cleanup table error: " + err.msg())
        <<
    }
    pool.close() >>> (err) {
        println("   [FAIL] Pool close error: " + err.msg())
        <<
    }
    println("   [PASS] MySQL Pool closed cleanly.")
}

fn main() {
    println("=== Xu MySQL / MariaDB Native Driver Verification ===\n")
    verify_mysql_live()
    verify_mysql_pool()
    println("\n[MYSQL VERIFICATION 100% COMPLETED]")
}
22_standalone_sqlite/main.xu

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@main

#database/sql/driver
sqlite #github.com/xulang-org/packages/sqlite
#os
#strings

fn remove_if_exists(p string) {
    os.remove(p) >>> (err) {
        <<
    }
}

fn main() int {
    println("=== SQLite Standalone Library Integration Test ===")

    db_file := "/tmp/xu_sqlite_test.db"
    remove_if_exists(strings.clone(&db_file))

    // 1. 打开数据库连接
    conn := sqlite.open(strings.clone(&db_file))

    // 2. 建表
    schema := "CREATE TABLE IF NOT EXISTS developers (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INT, salary REAL, active INT);"
    res1 := conn.exec(schema, []driver.NamedValue{})
    if res1.err.len > 0 {
        println("CREATE TABLE error: " + res1.err)
        << 1
    }
    println("1. Schema created successfully.")

    // 3. 参数化插入记录
    $args1 := []driver.NamedValue{}
    args1.push(driver.NamedValue{name: "name", ordinal: 1, value: "Ada Lovelace"})
    args1.push(driver.NamedValue{name: "age", ordinal: 2, value: 36})
    args1.push(driver.NamedValue{name: "salary", ordinal: 3, value: 125000.5})
    args1.push(driver.NamedValue{name: "active", ordinal: 4, value: true})

    res_ins1 := conn.exec("INSERT INTO developers (name, age, salary, active) VALUES (?, ?, ?, ?);", args1)
    if res_ins1.err.len > 0 {
        println("INSERT 1 error: " + res_ins1.err)
        << 1
    }
    println("2. Inserted developer 1, id=" + str(res_ins1.last_insert_id) + ", rows_affected=" + str(res_ins1.rows_affected))

    // 4. 第二条记录插入
    $args2 := []driver.NamedValue{}
    args2.push(driver.NamedValue{name: "name", ordinal: 1, value: "Alan Turing"})
    args2.push(driver.NamedValue{name: "age", ordinal: 2, value: 41})
    args2.push(driver.NamedValue{name: "salary", ordinal: 3, value: 140000.0})
    args2.push(driver.NamedValue{name: "active", ordinal: 4, value: true})

    res_ins2 := conn.exec("INSERT INTO developers (name, age, salary, active) VALUES (?, ?, ?, ?);", args2)
    if res_ins2.err.len > 0 {
        println("INSERT 2 error: " + res_ins2.err)
        << 1
    }
    println("3. Inserted developer 2, id=" + str(res_ins2.last_insert_id) + ", rows_affected=" + str(res_ins2.rows_affected))

    // 5. 查询所有记录
    rows := conn.query("SELECT id, name, age, salary, active FROM developers ORDER BY id ASC;", []driver.NamedValue{})
    if rows.err.len > 0 {
        println("QUERY error: " + rows.err)
        << 1
    }
    println("4. Query returned columns count: " + str(rows.ncols))
    $col_str := "   Columns: "
    for ci in 0:rows.columns.len {
        if ci > 0 {
            col_str = col_str + ", "
        }
        col_str = col_str + rows.columns[ci]
    }
    println(col_str)

    nrows := rows.cells.len / rows.ncols
    println("   Total rows: " + str(nrows))
    $r := 0
    while r < nrows {
        base := r * rows.ncols
        id_str := rows.cells[base]
        name_str := rows.cells[base + 1]
        age_str := rows.cells[base + 2]
        sal_str := rows.cells[base + 3]
        act_str := rows.cells[base + 4]
        println("   Row " + str(r + 1) + ": id=" + id_str + ", name=" + name_str + ", age=" + age_str + ", salary=" + sal_str + ", active=" + act_str)
        r = r + 1
    }

    // 6. 带参数的查询
    $qargs := []driver.NamedValue{}
    qargs.push(driver.NamedValue{name: "name", ordinal: 1, value: "Alan Turing"})
    rows_filtered := conn.query("SELECT id, name, age FROM developers WHERE name = ?;", qargs)
    if rows_filtered.err.len > 0 {
        println("FILTERED QUERY error: " + rows_filtered.err)
        << 1
    }
    if rows_filtered.cells.len >= 3 {
        println("5. Parameterized query successful: found " + rows_filtered.cells[1] + ", age=" + rows_filtered.cells[2])
    }

    // 7. 更新操作
    $uargs := []driver.NamedValue{}
    uargs.push(driver.NamedValue{name: "age", ordinal: 1, value: 37})
    uargs.push(driver.NamedValue{name: "id", ordinal: 2, value: 1})
    res_up := conn.exec("UPDATE developers SET age = ? WHERE id = ?;", uargs)
    if res_up.err.len > 0 {
        println("UPDATE error: " + res_up.err)
        << 1
    }
    println("6. Updated developer 1: rows_affected=" + str(res_up.rows_affected))

    // 8. 事务支持
    tx := conn.begin()
    $tx_args := []driver.NamedValue{}
    tx_args.push(driver.NamedValue{name: "name", ordinal: 1, value: "Grace Hopper"})
    tx_args.push(driver.NamedValue{name: "age", ordinal: 2, value: 85})
    tx_args.push(driver.NamedValue{name: "salary", ordinal: 3, value: 160000.0})
    tx_args.push(driver.NamedValue{name: "active", ordinal: 4, value: true})
    res_tx := conn.exec("INSERT INTO developers (name, age, salary, active) VALUES (?, ?, ?, ?);", tx_args)
    if res_tx.err.len > 0 {
        println("TX INSERT error: " + res_tx.err)
        << 1
    }
    commit_err := tx.commit()
    if commit_err.len > 0 {
        println("TX COMMIT error: " + commit_err)
        << 1
    }
    println("7. Transaction committed successfully.")

    // 9. 关闭与清理
    conn.close()
    remove_if_exists(db_file)
    println("=== SQLite Standalone Tests Completed Successfully! ===")
    << 0
}

API declarations

struct NamedValue

XuAPI
pub struct NamedValue {
    pub name string
    pub ordinal int
    pub value temp
}

Purpose

Structure encapsulating name, ordinal, value.

Public fields

name string
name
ordinal int
field (int)
value temp
field (temp)

See usage example

struct ExecResult

XuAPI
pub struct ExecResult {
    pub last_insert_id int
    pub rows_affected int
    pub err string
}

Purpose

Structure encapsulating last_insert_id, rows_affected, err.

Public fields

last_insert_id int
field (int)
rows_affected int
field (int)
err string
error

struct RowsResult

XuAPI
pub struct RowsResult {
    pub columns []string
    pub cells []string
    pub ncols int
    pub err string
}

Purpose

Structure encapsulating columns, cells, ncols, err.

Public fields

columns []string
field ([]string)
cells []string
field ([]string)
ncols int
field (int)
err string
error

struct Number

XuAPI
pub struct Number {
    pub n int
    pub ok bool
}

Purpose

Structure encapsulating n, ok.

Public fields

n int
count, length, or limit
ok bool
field (bool)

struct NullInfo

XuAPI
pub struct NullInfo {
    pub nullable bool
    pub ok bool
}

Purpose

Structure encapsulating nullable, ok.

Public fields

nullable bool
field (bool)
ok bool
field (bool)

struct DecimalSize

XuAPI
pub struct DecimalSize {
    pub precision int
    pub scale int
    pub ok bool
}

Purpose

Structure encapsulating precision, scale, ok.

Public fields

precision int
field (int)
scale int
field (int)
ok bool
field (bool)

struct Null

XuAPI
pub struct Null {

}

Purpose

Null context or state structure.

Public fields

This type has no public fields.

struct@ Stmt

XuAPI
struct@ Stmt {
    fn num_input() int
    fn exec([]NamedValue) ExecResult
    fn query([]NamedValue) RowsResult
    fn close() string
}

Purpose

Method-set constraint Stmt.

Required methods

num_input fn num_input() int
Operation on Stmt: num input.
exec fn exec([]NamedValue) ExecResult
Execute SQL statement or service command and return result.
query fn query([]NamedValue) RowsResult
Execute query on Stmt.
close fn close() string
Operation on Stmt: close the resource.

(Stmt) num_input

XuAPI
fn num_input() int

Purpose

Operation on Stmt: num input.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

int — a value of this type

(Stmt) exec

XuAPI
fn exec([]NamedValue) ExecResult

Purpose

Execute SQL statement or service command and return result.

Parameters

self Self
The Self instance used by this call (value receiver).
namedValue []NamedValue
namedValue ([]NamedValue)

Returns

ExecResult — a value of this type

(Stmt) query

XuAPI
fn query([]NamedValue) RowsResult

Purpose

Execute query on Stmt.

Parameters

self Self
The Self instance used by this call (value receiver).
namedValue []NamedValue
namedValue ([]NamedValue)

Returns

RowsResult — a value of this type

(Stmt) close

XuAPI
fn close() string

Purpose

Operation on Stmt: close the resource.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

string — result string

struct@ Tx

XuAPI
struct@ Tx {
    fn commit() string
    fn rollback() string
}

Purpose

Method-set constraint Tx.

Required methods

commit fn commit() string
Execute commit on Tx.
rollback fn rollback() string
Execute rollback on Tx.

(Tx) commit

XuAPI
fn commit() string

Purpose

Execute commit on Tx.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

string — result string

(Tx) rollback

XuAPI
fn rollback() string

Purpose

Execute rollback on Tx.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

string — result string

struct@ Conn

XuAPI
struct@ Conn {
    fn ping() string
    fn exec(string, []NamedValue) ExecResult
    fn query(string, []NamedValue) RowsResult
    fn close() string
    fn dup() Conn
    fn prepare(string) Stmt
    fn prepare_context(&context.Context, string) Stmt
    fn begin() Tx
    fn begin_tx(int, bool) Tx
    fn reset_session(&context.Context) string
    fn is_valid() bool
}

Purpose

Method-set constraint Conn.

Required methods

ping fn ping() string
Send a ping heartbeat request to verify connection liveness.
exec fn exec(string, []NamedValue) ExecResult
Execute SQL statement or service command and return result.
query fn query(string, []NamedValue) RowsResult
Execute query on Conn.
close fn close() string
Operation on Conn: close the resource.
dup fn dup() Conn
Create and return a duplicate object holding independent state.
prepare fn prepare(string) Stmt
Execute prepare on Conn.
prepare_context fn prepare_context(&context.Context, string) Stmt
Operation on Conn: prepare context.
begin fn begin() Tx
Execute begin on Conn.
begin_tx fn begin_tx(int, bool) Tx
Operation on Conn: begin tx.
reset_session fn reset_session(&context.Context) string
Operation on Conn: reset session.
is_valid fn is_valid() bool
Operation on Conn: whether it is valid.

(Conn) ping

XuAPI
fn ping() string

Purpose

Send a ping heartbeat request to verify connection liveness.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

string — result string

(Conn) exec

XuAPI
fn exec(string, []NamedValue) ExecResult

Purpose

Execute SQL statement or service command and return result.

Parameters

self Self
The Self instance used by this call (value receiver).
string string
string (string)
namedValue []NamedValue
namedValue ([]NamedValue)

Returns

ExecResult — a value of this type

(Conn) query

XuAPI
fn query(string, []NamedValue) RowsResult

Purpose

Execute query on Conn.

Parameters

self Self
The Self instance used by this call (value receiver).
string string
string (string)
namedValue []NamedValue
namedValue ([]NamedValue)

Returns

RowsResult — a value of this type

(Conn) close

XuAPI
fn close() string

Purpose

Operation on Conn: close the resource.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

string — result string

(Conn) dup

XuAPI
fn dup() Conn

Purpose

Create and return a duplicate object holding independent state.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

Conn — a value of this type

(Conn) prepare

XuAPI
fn prepare(string) Stmt

Purpose

Execute prepare on Conn.

Parameters

self Self
The Self instance used by this call (value receiver).
string string
string (string)

Returns

Stmt — a value of this type

(Conn) prepare_context

XuAPI
fn prepare_context(&context.Context, string) Stmt

Purpose

Operation on Conn: prepare context.

Parameters

self Self
The Self instance used by this call (value receiver).
context &context.Context
context (read-only borrow; caller keeps the original; type &context.Context)
string string
string (string)

Returns

Stmt — a value of this type

(Conn) begin

XuAPI
fn begin() Tx

Purpose

Execute begin on Conn.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

Tx — a value of this type

(Conn) begin_tx

XuAPI
fn begin_tx(int, bool) Tx

Purpose

Operation on Conn: begin tx.

Parameters

self Self
The Self instance used by this call (value receiver).
int int
int (int)
bool bool
bool (bool)

Returns

Tx — a value of this type

(Conn) reset_session

XuAPI
fn reset_session(&context.Context) string

Purpose

Operation on Conn: reset session.

Parameters

self Self
The Self instance used by this call (value receiver).
context &context.Context
context (read-only borrow; caller keeps the original; type &context.Context)

Returns

string — result string

(Conn) is_valid

XuAPI
fn is_valid() bool

Purpose

Operation on Conn: whether it is valid.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

bool — true or false

struct@ Driver

XuAPI
struct@ Driver {
    fn open(string) Conn
    fn dup() Driver
}

Purpose

Method-set constraint Driver.

Required methods

open fn open(string) Conn
Operation on Driver: open resource or establish connection.
dup fn dup() Driver
Create and return a duplicate object holding independent state.

(Driver) open

XuAPI
fn open(string) Conn

Purpose

Operation on Driver: open resource or establish connection.

Parameters

self Self
The Self instance used by this call (value receiver).
string string
string (string)

Returns

Conn — a value of this type

(Driver) dup

XuAPI
fn dup() Driver

Purpose

Create and return a duplicate object holding independent state.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

Driver — a value of this type

struct@ Connector

XuAPI
struct@ Connector {
    fn connect(&context.Context) Conn
    fn driver() Driver
}

Purpose

Method-set constraint Connector.

Required methods

connect fn connect(&context.Context) Conn
Establish network connection to the target server endpoint.
driver fn driver() Driver
Operation on Connector: return the database driver instance implementing driver.Driver.

(Connector) connect

XuAPI
fn connect(&context.Context) Conn

Purpose

Establish network connection to the target server endpoint.

Parameters

self Self
The Self instance used by this call (value receiver).
context &context.Context
context (read-only borrow; caller keeps the original; type &context.Context)

Returns

Conn — a value of this type

(Connector) driver

XuAPI
fn driver() Driver

Purpose

Operation on Connector: return the database driver instance implementing driver.Driver.

Parameters

self Self
The Self instance used by this call (value receiver).

Returns

Driver — a value of this type

encode_value

XuAPI
pub fn encode_value(v temp) string

Purpose

Encode value data.

Parameters

v temp
value (temp)

Returns

string — result string

decode_value_checked

XuAPI
pub fn decode_value_checked(s string) temp

Purpose

Decode value checked data. Throws on failure; handle the error or propagate it to the caller.

Parameters

s string
source string (string)

Returns

temp — a value of this type

decode_value

XuAPI
pub fn decode_value(s string) temp

Purpose

Decode value data.

Parameters

s string
source string (string)

Returns

temp — a value of this type

exec_ok

XuAPI
pub fn exec_ok(id int, n int) ExecResult

Purpose

Build an ExecResult indicating successful statement execution.

Parameters

id int
id (int)
n int
count, length, or limit (int)

Returns

ExecResult — a value of this type

exec_err

XuAPI
pub fn exec_err(msg string) ExecResult

Purpose

Build an ExecResult indicating statement execution failure.

Parameters

msg string
message (string)

Returns

ExecResult — a value of this type

rows_err

XuAPI
pub fn rows_err(msg string) RowsResult

Purpose

Build a RowsResult indicating query error.

Parameters

msg string
message (string)

Returns

RowsResult — a value of this type

err_bad_conn

XuAPI
pub fn err_bad_conn() string

Purpose

driver.ErrBadConn. sql retries with a new connection.

Parameters

No arguments are required.

Returns

string — result string

is_bad_conn

XuAPI
pub fn is_bad_conn(msg string) bool

Purpose

Whether it is bad conn.

Parameters

msg string
message (string)

Returns

bool — true or false