XU XUv0.16.0

#database/sql

import: #database/sql

counts: 9 functions, 63 methods, 18 types, 8 constants, 0 method sets

Insert a row with SQLite

Use database/sql with a concrete driver to manage a connection pool and execute SQL.

open takes a driver object and a driver-specific DSN; it opens connections lazily. This example uses SQLite in memory, checks operation errors and closes the pool explicitly.

Prerequisite: use the official packages checkout and build the SQLite native bridge for your target. Add this dependency to your project’s xu.xun, replacing the path with that checkout:

require:
  "github.com/xulang-org/packages": file:/path/to/packages

See the MySQL quickstart for a server-backed driver and its DSN. MySQL service integration here: 待验 (not verified).

Save the complete program as main.xu and check it with xu check main.xu. One-step linking of native static libraries is supported on macOS arm64/x64, where you can use xu run main.xu; Linux requires object emission and a separate linker step. This example passed the SDK check; native execution is 待验 (not verified).

@main
#database/sql
sqlite #github.com/xulang-org/packages/sqlite

fn main() int {
    $db := sql.open(sqlite.driver(), ":memory:")
    db.exec("CREATE TABLE notes (body TEXT)") >>> (err) {
        println(err.msg())
        << 1
    }
    result := db.exec("INSERT INTO notes VALUES ('hello')") >>> (err) {
        println(err.msg())
        << 1
    }
    println(result.rows_affected())
    db.close() >>> (err) {
        println(err.msg())
        << 1
    }
    << 0
}

Expected output: 1 (the inserted row count).

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.

18_database_mysql/main.xu

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@main

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

// MySQL/MariaDB:XU_MYSQL_DSN 可覆盖本地开发默认值。
// 驱动是普通 XU 包,通过 database/sql 接口使用,不依赖编译器内建。

fn main() int {
    $dsn := os.getenv("XU_MYSQL_DSN")
    if dsn.len == 0 {
        dsn = "root:root@tcp(127.0.0.1:3306)/xu_demo?tls=false"
    }

    $db := sql.open(mysql.driver(), dsn)
    db.ping() >>> (err) {
        println("MySQL ping failed")
        println(err.msg())
        << 1
    }

    db.exec("DROP TABLE IF EXISTS xu_people") >>> (err) {
        println(err.msg())
        << 1
    }
    db.exec("CREATE TABLE xu_people (id INTEGER PRIMARY KEY, name VARCHAR(100) NOT NULL, active BOOLEAN NOT NULL)") >>> (err) {
        println(err.msg())
        << 1
    }

    first := db.exec(
        "INSERT INTO xu_people (id, name, active) VALUES (?, ?, ?)",
        1,
        "Ada",
        true
    ) >>> (err) {
        println(err.msg())
        << 1
    }
    println("inserted=" + str(first.rows_affected()))

    $insert_person := db.prepare(
        "INSERT INTO xu_people (id, name, active) VALUES (?, ?, ?)"
    ) >>> (err) {
        println(err.msg())
        << 1
    }
    insert_person.exec(2, "Lin", true) >>> (err) {
        println(err.msg())
        << 1
    }
    insert_person.close()

    $tx := db.begin() >>> (err) {
        println(err.msg())
        << 1
    }
    tx.exec(
        "INSERT INTO xu_people (id, name, active) VALUES (?, ?, ?)",
        3,
        "Grace",
        true
    ) >>> (err) {
        println(err.msg())
        << 1
    }
    tx.commit() >>> (err) {
        println(err.msg())
        << 1
    }

    $rows := db.query("SELECT id, name FROM xu_people ORDER BY id") >>> (err) {
        println(err.msg())
        << 1
    }
    while rows.next() {
        values := rows.take() >>> (err) {
            println(err.msg())
            << 1
        }
        id := values[0] as int
        name := values[1] as string
        println(str(id) + ": " + name)
    }
    if rows.err().len > 0 {
        println(rows.err())
        << 1
    }
    rows.close()

    row := db.query_row("SELECT name FROM xu_people WHERE id = ?", 2)
    values := row.take() >>> (err) {
        println(err.msg())
        << 1
    }
    println("selected=" + (values[0] as string))

    db.close() >>> (err) {
        println(err.msg())
        << 1
    }
    << 0
}
17_database_postgres/main.xu

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@main

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

// PostgreSQL:XU_POSTGRES_DSN 可覆盖本地开发默认值。
// 驱动是普通 XU 包,通过 database/sql 接口使用,不依赖编译器内建。

fn main() int {
    $dsn := os.getenv("XU_POSTGRES_DSN")
    if dsn.len == 0 {
        dsn = "postgres://postgres:postgres@127.0.0.1:5432/xu_demo?sslmode=disable"
    }

    $db := sql.open(postgres.driver(), dsn)
    db.ping() >>> (err) {
        println("PostgreSQL ping failed")
        println(err.msg())
        << 1
    }

    db.exec("DROP TABLE IF EXISTS xu_people") >>> (err) {
        println(err.msg())
        << 1
    }
    db.exec("CREATE TABLE xu_people (id INTEGER PRIMARY KEY, name VARCHAR(100) NOT NULL, active BOOLEAN NOT NULL)") >>> (err) {
        println(err.msg())
        << 1
    }

    first := db.exec(
        "INSERT INTO xu_people (id, name, active) VALUES ($$1, $$2, $$3)",
        1,
        "Ada",
        true
    ) >>> (err) {
        println(err.msg())
        << 1
    }
    println("inserted=" + str(first.rows_affected()))

    $insert_person := db.prepare(
        "INSERT INTO xu_people (id, name, active) VALUES ($$1, $$2, $$3)"
    )
    insert_person.exec(2, "Lin", true) >>> (err) {
        println(err.msg())
        << 1
    }
    insert_person.close()

    $tx := db.begin() >>> (err) {
        println(err.msg())
        << 1
    }
    tx.exec(
        "INSERT INTO xu_people (id, name, active) VALUES ($$1, $$2, $$3)",
        3,
        "Grace",
        true
    ) >>> (err) {
        println(err.msg())
        << 1
    }
    tx.commit() >>> (err) {
        println(err.msg())
        << 1
    }

    $rows := db.query("SELECT id, name FROM xu_people ORDER BY id") >>> (err) {
        println(err.msg())
        << 1
    }
    while rows.next() {
        values := rows.take() >>> (err) {
            println(err.msg())
            << 1
        }
        id := values[0] as int
        name := values[1] as string
        println(str(id) + ": " + name)
    }
    if rows.err().len > 0 {
        println(rows.err())
        << 1
    }
    rows.close()

    $qrows := db.query("SELECT name FROM xu_people WHERE id = $$1", 2) >>> (err) {
        println(err.msg())
        << 1
    }
    if qrows.next() {
        vals := qrows.take() >>> (err) {
            println(err.msg())
            << 1
        }
        println("selected=" + (vals[0] as string))
    }
    qrows.close()

    db.close() >>> (err) {
        println(err.msg())
        << 1
    }
    << 0
}

API declarations

const LEVEL_DEFAULT

XuAPI
pub const LEVEL_DEFAULT = 0

Purpose

Default transaction isolation level determined by the driver or server.

const LEVEL_READ_UNCOMMITTED

XuAPI
pub const LEVEL_READ_UNCOMMITTED = 1

Purpose

Read Uncommitted transaction isolation level permitting dirty reads.

const LEVEL_READ_COMMITTED

XuAPI
pub const LEVEL_READ_COMMITTED = 2

Purpose

Read Committed transaction isolation level preventing dirty reads.

const LEVEL_WRITE_COMMITTED

XuAPI
pub const LEVEL_WRITE_COMMITTED = 3

Purpose

Constant LEVEL_WRITE_COMMITTED, defining protocol or algorithm parameters.

const LEVEL_REPEATABLE_READ

XuAPI
pub const LEVEL_REPEATABLE_READ = 4

Purpose

Repeatable Read transaction isolation level preventing non-repeatable reads.

const LEVEL_SNAPSHOT

XuAPI
pub const LEVEL_SNAPSHOT = 5

Purpose

Constant LEVEL_SNAPSHOT, defining protocol or algorithm parameters.

const LEVEL_SERIALIZABLE

XuAPI
pub const LEVEL_SERIALIZABLE = 6

Purpose

Serializable transaction isolation level; support depends on the driver and database.

const LEVEL_LINEARIZABLE

XuAPI
pub const LEVEL_LINEARIZABLE = 7

Purpose

Constant LEVEL_LINEARIZABLE, defining protocol or algorithm parameters.

struct TxOptions

XuAPI
pub struct TxOptions {
    pub isolation int
    pub read_only bool
}

Purpose

Sql Configuration parameters and options set.

Public fields

isolation int
field (int)
read_only bool
field (bool)

struct NamedArg

XuAPI
pub struct NamedArg {
    pub name string
    pub value temp
}

Purpose

Structure encapsulating name, value.

Public fields

name string
name
value temp
field (temp)

struct DBStats

XuAPI
pub struct DBStats {
    pub max_open_connections int
    pub open_connections int
    pub in_use int
    pub idle int
    pub wait_count int
    pub max_idle_closed int
    pub max_idle_time_closed int
    pub max_lifetime_closed int
}

Purpose

sql.DBStats (WaitDuration omitted: v1 does not accumulate wait ns).

Public fields

max_open_connections int
field (int)
open_connections int
field (int)
in_use int
field (int)
idle int
field (int)
wait_count int
field (int)
max_idle_closed int
field (int)
max_idle_time_closed int
field (int)
max_lifetime_closed int
field (int)

struct DB

XuAPI
pub struct DB {
    pub drv driver.Driver
    pub dsn string
    pub use_connector int
    pub opener chan ConnSlot
    pub idle chan PooledConn
    pub st chan PoolState
}

Purpose

Concurrency-safe database connection pool managing idle connections and transactions.

Public fields

drv driver.Driver
field (driver.Driver)
dsn string
field (string)
use_connector int
field (int)
opener chan ConnSlot
field (channel; type chan ConnSlot)
idle chan PooledConn
field (channel; type chan PooledConn)
st chan PoolState
field (channel; type chan PoolState)

struct Conn

XuAPI
pub struct Conn {
    pub closed int
    pub slot chan PooledConn
    pub created_ns int
    pub idle_ns int
    pub idle chan PooledConn
    pub pst chan PoolState
    pub drv driver.Driver
    pub dsn string
    pub use_connector int
    pub opener chan ConnSlot
}

Purpose

Structure encapsulating closed, slot, created_ns, idle_ns, idle.

Public fields

closed int
field (int)
slot chan PooledConn
field (channel; type chan PooledConn)
created_ns int
field (int)
idle_ns int
field (int)
idle chan PooledConn
field (channel; type chan PooledConn)
pst chan PoolState
field (channel; type chan PoolState)
drv driver.Driver
field (driver.Driver)
dsn string
field (string)
use_connector int
field (int)
opener chan ConnSlot
field (channel; type chan ConnSlot)

struct Tx

XuAPI
pub struct Tx {
    pub slot chan PooledConn
    pub dtx driver.Tx
    pub done int
    pub from_pool int
    pub created_ns int
    pub idle_ns int
    pub idle chan PooledConn
    pub pst chan PoolState
    pub drv driver.Driver
    pub dsn string
    pub use_connector int
    pub opener chan ConnSlot
}

Purpose

In-flight transaction on dedicated database connection; must end with commit or rollback.

Public fields

slot chan PooledConn
field (channel; type chan PooledConn)
dtx driver.Tx
field (driver.Tx)
done int
field (int)
from_pool int
field (int)
created_ns int
field (int)
idle_ns int
field (int)
idle chan PooledConn
field (channel; type chan PooledConn)
pst chan PoolState
field (channel; type chan PoolState)
drv driver.Driver
field (driver.Driver)
dsn string
field (string)
use_connector int
field (int)
opener chan ConnSlot
field (channel; type chan ConnSlot)

struct Result

XuAPI
pub struct Result {
    pub last_insert_id int
    pub rows_affected int
}

Purpose

Structure encapsulating last_insert_id, rows_affected.

Public fields

last_insert_id int
field (int)
rows_affected int
field (int)

struct NullInt64

XuAPI
pub struct NullInt64 {
    pub v int
    pub valid bool
}

Purpose

Structure encapsulating v, valid.

Public fields

v int
value
valid bool
field (bool)

struct NullString

XuAPI
pub struct NullString {
    pub s string
    pub valid bool
}

Purpose

Structure encapsulating s, valid.

Public fields

s string
source string
valid bool
field (bool)

struct NullBool

XuAPI
pub struct NullBool {
    pub v bool
    pub valid bool
}

Purpose

Structure encapsulating v, valid.

Public fields

v bool
value
valid bool
field (bool)

struct NullFloat64

XuAPI
pub struct NullFloat64 {
    pub v f64
    pub valid bool
}

Purpose

Structure encapsulating v, valid.

Public fields

v f64
value
valid bool
field (bool)

struct NullInt32

XuAPI
pub struct NullInt32 {
    pub v i32
    pub valid bool
}

Purpose

Structure encapsulating v, valid.

Public fields

v i32
value
valid bool
field (bool)

struct NullByte

XuAPI
pub struct NullByte {
    pub v u8
    pub valid bool
}

Purpose

Structure encapsulating v, valid.

Public fields

v u8
value
valid bool
field (bool)

struct NullTime

XuAPI
pub struct NullTime {
    pub t time.Time
    pub valid bool
}

Purpose

Structure encapsulating t, valid.

Public fields

t time.Time
field (time.Time)
valid bool
field (bool)

struct ColumnType

XuAPI
pub struct ColumnType {
    pub col string
    pub db_type string
    pub length int
    pub length_ok bool
    pub nullable bool
    pub nullable_ok bool
    pub precision int
    pub scale int
    pub precision_ok bool
}

Purpose

Structure encapsulating col, db_type, length, length_ok, nullable.

Public fields

col string
field (string)
db_type string
field (string)
length int
field (int)
length_ok bool
field (bool)
nullable bool
field (bool)
nullable_ok bool
field (bool)
precision int
field (int)
scale int
field (int)
precision_ok bool
field (bool)

struct Rows

XuAPI
pub struct Rows {
    pub cols []string
    pub cells []string
    pub cur []string
    pub ncols int
    pub i int
    pub closed int
    pub err string
    pub has int
    pub pooled int
    pub idle chan PooledConn
    pub pst chan PoolState
}

Purpose

SQL query result iterator cursor; iterate rows and close after use.

Public fields

cols []string
field ([]string)
cells []string
field ([]string)
cur []string
field ([]string)
ncols int
field (int)
i int
index or integer
closed int
field (int)
err string
error
has int
field (int)
pooled int
field (int)
idle chan PooledConn
field (channel; type chan PooledConn)
pst chan PoolState
field (channel; type chan PoolState)

struct Row

XuAPI
pub struct Row {
    pub cells []string
    pub err string
}

Purpose

Structure encapsulating cells, err.

Public fields

cells []string
field ([]string)
err string
error

struct Stmt

XuAPI
pub struct Stmt {
    pub ds driver.Stmt
    pub qtext string
    pub closed int
    pub from_db int
    pub created_ns int
    pub idle_ns int
    pub idle chan PooledConn
    pub pst chan PoolState
    pub drv driver.Driver
    pub dsn string
    pub use_connector int
    pub opener chan ConnSlot
}

Purpose

Structure encapsulating ds, qtext, closed, from_db, created_ns.

Public fields

ds driver.Stmt
field (driver.Stmt)
qtext string
field (string)
closed int
field (int)
from_db int
field (int)
created_ns int
field (int)
idle_ns int
field (int)
idle chan PooledConn
field (channel; type chan PooledConn)
pst chan PoolState
field (channel; type chan PoolState)
drv driver.Driver
field (driver.Driver)
dsn string
field (string)
use_connector int
field (int)
opener chan ConnSlot
field (channel; type chan ConnSlot)

named

XuAPI
pub fn named(name string, value temp) NamedArg

Purpose

Construct a named SQL parameter (NamedArg).

Parameters

name string
name (string)
value temp
value (temp)

Returns

NamedArg — a value of this type

open

XuAPI
pub fn open(d driver.Driver, name string) DB

Purpose

Create a database pool DB from a driver object and DSN; open connections lazily on first use.

Parameters

d driver.Driver
concrete driver object, such as sqlite.driver() or mysql.driver()
name string
data source name (DSN) interpreted by the driver

Returns

database pool instance DB

See usage example

open_db

XuAPI
pub fn open_db(c driver.Connector) DB

Purpose

Open db.

Parameters

c driver.Connector
byte or character code (driver.Connector)

Returns

DB — a value of this type

open_db_context

XuAPI
pub fn open_db_context(ctx &context.Context, c driver.Connector) DB

Purpose

Open db context. Throws on failure; handle the error or propagate it to the caller.

Parameters

ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
c driver.Connector
byte or character code (driver.Connector)

Returns

DB — a value of this type

is_no_rows

XuAPI
pub fn is_no_rows(e errors.Error) bool

Purpose

Whether it is no rows.

Parameters

e errors.Error
e (errors.Error)

Returns

bool — true or false

is_tx_done

XuAPI
pub fn is_tx_done(e errors.Error) bool

Purpose

Whether it is tx done.

Parameters

e errors.Error
e (errors.Error)

Returns

bool — true or false

is_conn_done

XuAPI
pub fn is_conn_done(e errors.Error) bool

Purpose

Whether it is conn done.

Parameters

e errors.Error
e (errors.Error)

Returns

bool — true or false

is_bad_conn

XuAPI
pub fn is_bad_conn(e errors.Error) bool

Purpose

Whether it is bad conn.

Parameters

e errors.Error
e (errors.Error)

Returns

bool — true or false

isolation_name

XuAPI
pub fn isolation_name(level int) string

Purpose

Isolation name.

Parameters

level int
level (int)

Returns

string — result string

(&DB) driver

XuAPI
pub fn (db &DB) driver() driver.Driver

Purpose

Operation on &DB: return the database driver instance implementing driver.Driver.

Parameters

db &DB
The DB instance used by this call (borrow).

Returns

driver.Driver — a value of this type

(&DB) ping

XuAPI
pub fn (db &DB) ping() int

Purpose

Send a ping heartbeat request to verify connection liveness. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).

Returns

int — a value of this type

(&DB) ping_context

XuAPI
pub fn (db &DB) ping_context(ctx &context.Context) int

Purpose

Operation on &DB: ping context. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)

Returns

int — a value of this type

(&DB) exec

XuAPI
pub fn (db &DB) exec(query string, args <-> temp) Result

Purpose

Execute SQL statement or service command and return result. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Result — a value of this type

(&DB) exec_context

XuAPI
pub fn (db &DB) exec_context(ctx &context.Context, query string, args <-> temp) Result

Purpose

Operation on &DB: exec context. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Result — a value of this type

(&DB) query

XuAPI
pub fn (db &DB) query(query string, args <-> temp) Rows

Purpose

Execute query on &DB. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Rows — a value of this type

(&DB) query_context

XuAPI
pub fn (db &DB) query_context(ctx &context.Context, query string, args <-> temp) Rows

Purpose

Operation on &DB: query context. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Rows — a value of this type

(&DB) query_row

XuAPI
pub fn (db &DB) query_row(query string, args <-> temp) Row

Purpose

Operation on &DB: query row.

Parameters

db &DB
The DB instance used by this call (borrow).
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Row — a value of this type

(&DB) query_row_context

XuAPI
pub fn (db &DB) query_row_context(ctx &context.Context, query string, args <-> temp) Row

Purpose

Operation on &DB: query row context.

Parameters

db &DB
The DB instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Row — a value of this type

(&DB) prepare

XuAPI
pub fn (db &DB) prepare(query string) Stmt

Purpose

Execute prepare on &DB. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
query string
query (string)

Returns

Stmt — a value of this type

(&DB) prepare_context

XuAPI
pub fn (db &DB) prepare_context(ctx &context.Context, query string) Stmt

Purpose

Operation on &DB: prepare context. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)

Returns

Stmt — a value of this type

(&DB) begin

XuAPI
pub fn (db &DB) begin() Tx

Purpose

Execute begin on &DB. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).

Returns

Tx — a value of this type

(&DB) begin_tx

XuAPI
pub fn (db &DB) begin_tx(ctx &context.Context, opts TxOptions) Tx

Purpose

Operation on &DB: begin tx. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
opts TxOptions
opts (TxOptions)

Returns

Tx — a value of this type

(&DB) set_max_open_conns

XuAPI
pub fn (db &DB) set_max_open_conns(n int)

Purpose

Operation on &DB: set max open conns.

Parameters

db &DB
The DB instance used by this call (borrow).
n int
count, length, or limit (int)

Returns

This call does not return a value.

(&DB) set_max_idle_conns

XuAPI
pub fn (db &DB) set_max_idle_conns(n int)

Purpose

Operation on &DB: set max idle conns.

Parameters

db &DB
The DB instance used by this call (borrow).
n int
count, length, or limit (int)

Returns

This call does not return a value.

(&DB) set_conn_max_lifetime

XuAPI
pub fn (db &DB) set_conn_max_lifetime(d int)

Purpose

Operation on &DB: set conn max lifetime.

Parameters

db &DB
The DB instance used by this call (borrow).
d int
d (int)

Returns

This call does not return a value.

(&DB) set_conn_max_idle_time

XuAPI
pub fn (db &DB) set_conn_max_idle_time(d int)

Purpose

Operation on &DB: set conn max idle time.

Parameters

db &DB
The DB instance used by this call (borrow).
d int
d (int)

Returns

This call does not return a value.

(&DB) stats

XuAPI
pub fn (db &DB) stats() DBStats

Purpose

Execute stats on &DB.

Parameters

db &DB
The DB instance used by this call (borrow).

Returns

DBStats — a value of this type

($&DB) close

XuAPI
pub fn (db $&DB) close() int

Purpose

Operation on $&DB: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

db $&DB
The DB instance used by this call (exclusive borrow).

Returns

int — a value of this type

(&DB) conn

XuAPI
pub fn (db &DB) conn(ctx &context.Context) Conn

Purpose

Operation on &DB: connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

db &DB
The DB instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)

Returns

Conn — a value of this type

(&Conn) ping_context

XuAPI
pub fn (c &Conn) ping_context(ctx &context.Context) int

Purpose

Operation on &Conn: ping context. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)

Returns

int — a value of this type

(&Conn) exec_context

XuAPI
pub fn (c &Conn) exec_context(ctx &context.Context, query string, args <-> temp) Result

Purpose

Operation on &Conn: exec context. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Result — a value of this type

(&Conn) query_context

XuAPI
pub fn (c &Conn) query_context(ctx &context.Context, query string, args <-> temp) Rows

Purpose

Operation on &Conn: query context. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Rows — a value of this type

(&Conn) query_row_context

XuAPI
pub fn (c &Conn) query_row_context(ctx &context.Context, query string, args <-> temp) Row

Purpose

Operation on &Conn: query row context.

Parameters

c &Conn
The Conn instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Row — a value of this type

(&Conn) raw

XuAPI
pub fn (c &Conn) raw() driver.Conn

Purpose

Execute raw on &Conn. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).

Returns

driver.Conn — a value of this type

(&Conn) prepare_context

XuAPI
pub fn (c &Conn) prepare_context(ctx &context.Context, query string) Stmt

Purpose

Operation on &Conn: prepare context. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)

Returns

Stmt — a value of this type

(&Conn) begin_tx

XuAPI
pub fn (c &Conn) begin_tx(ctx &context.Context, opts TxOptions) Tx

Purpose

Operation on &Conn: begin tx. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
opts TxOptions
opts (TxOptions)

Returns

Tx — a value of this type

($&Conn) close

XuAPI
pub fn (c $&Conn) close() int

Purpose

Operation on $&Conn: close the resource.

Parameters

c $&Conn
The Conn instance used by this call (exclusive borrow).

Returns

int — a value of this type

(Result) last_insert_id

XuAPI
pub fn (r Result) last_insert_id() int

Purpose

Operation on Result: last insert id.

Parameters

r Result
The Result instance used by this call (value receiver).

Returns

int — a value of this type

(Result) rows_affected

XuAPI
pub fn (r Result) rows_affected() int

Purpose

Operation on Result: rows affected.

Parameters

r Result
The Result instance used by this call (value receiver).

Returns

int — a value of this type

($&Rows) next

XuAPI
pub fn (r $&Rows) next() bool

Purpose

Operation on $&Rows: take the next item, or end according to this type.

Parameters

r $&Rows
The Rows instance used by this call (exclusive borrow).

Returns

bool — true or false

($&Rows) take

XuAPI
pub fn (r $&Rows) take() []temp

Purpose

Execute take on $&Rows. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Rows
The Rows instance used by this call (exclusive borrow).

Returns

[]temp — slice result

(&Rows) columns

XuAPI
pub fn (r &Rows) columns() []string

Purpose

Execute columns on &Rows.

Parameters

r &Rows
The Rows instance used by this call (borrow).

Returns

[]string — slice result

($&Rows) close

XuAPI
pub fn (r $&Rows) close()

Purpose

Operation on $&Rows: close the resource.

Parameters

r $&Rows
The Rows instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Rows) err

XuAPI
pub fn (r &Rows) err() string

Purpose

Execute err on &Rows.

Parameters

r &Rows
The Rows instance used by this call (borrow).

Returns

string — result string

(ColumnType) name

XuAPI
pub fn (ct ColumnType) name() string

Purpose

Execute name on ColumnType.

Parameters

ct ColumnType
The ColumnType instance used by this call (value receiver).

Returns

string — result string

(ColumnType) database_type_name

XuAPI
pub fn (ct ColumnType) database_type_name() string

Purpose

Operation on ColumnType: database type name.

Parameters

ct ColumnType
The ColumnType instance used by this call (value receiver).

Returns

string — result string

(ColumnType) length

XuAPI
pub fn (ct ColumnType) length() driver.Number

Purpose

Operation on ColumnType: return the current length.

Parameters

ct ColumnType
The ColumnType instance used by this call (value receiver).

Returns

driver.Number — a value of this type

(ColumnType) nullable

XuAPI
pub fn (ct ColumnType) nullable() driver.NullInfo

Purpose

Execute nullable on ColumnType.

Parameters

ct ColumnType
The ColumnType instance used by this call (value receiver).

Returns

driver.NullInfo — a value of this type

(ColumnType) decimal_size

XuAPI
pub fn (ct ColumnType) decimal_size() driver.DecimalSize

Purpose

Operation on ColumnType: decimal size.

Parameters

ct ColumnType
The ColumnType instance used by this call (value receiver).

Returns

driver.DecimalSize — a value of this type

(&Rows) column_types

XuAPI
pub fn (r &Rows) column_types() []ColumnType

Purpose

Operation on &Rows: column types.

Parameters

r &Rows
The Rows instance used by this call (borrow).

Returns

[]ColumnType — slice result

($&Rows) next_result_set

XuAPI
pub fn (r $&Rows) next_result_set() bool

Purpose

Operation on $&Rows: next result set.

Parameters

r $&Rows
The Rows instance used by this call (exclusive borrow).

Returns

bool — true or false

(&Row) err

XuAPI
pub fn (r &Row) err() string

Purpose

Execute err on &Row.

Parameters

r &Row
The Row instance used by this call (borrow).

Returns

string — result string

(&Row) take

XuAPI
pub fn (r &Row) take() []temp

Purpose

Execute take on &Row. Throws on failure; handle the error or propagate it to the caller.

Parameters

r &Row
The Row instance used by this call (borrow).

Returns

[]temp — slice result

(&Tx) exec

XuAPI
pub fn (t &Tx) exec(query string, args <-> temp) Result

Purpose

Execute SQL statement or service command and return result. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Result — a value of this type

(&Tx) exec_context

XuAPI
pub fn (t &Tx) exec_context(ctx &context.Context, query string, args <-> temp) Result

Purpose

Operation on &Tx: exec context. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Result — a value of this type

(&Tx) query

XuAPI
pub fn (t &Tx) query(query string, args <-> temp) Rows

Purpose

Execute query on &Tx. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Rows — a value of this type

(&Tx) query_context

XuAPI
pub fn (t &Tx) query_context(ctx &context.Context, query string, args <-> temp) Rows

Purpose

Operation on &Tx: query context. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Rows — a value of this type

(&Tx) query_row

XuAPI
pub fn (t &Tx) query_row(query string, args <-> temp) Row

Purpose

Operation on &Tx: query row.

Parameters

t &Tx
The Tx instance used by this call (borrow).
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Row — a value of this type

(&Tx) query_row_context

XuAPI
pub fn (t &Tx) query_row_context(ctx &context.Context, query string, args <-> temp) Row

Purpose

Operation on &Tx: query row context.

Parameters

t &Tx
The Tx instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Row — a value of this type

(&Tx) prepare

XuAPI
pub fn (t &Tx) prepare(query string) Stmt

Purpose

Execute prepare on &Tx. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
query string
query (string)

Returns

Stmt — a value of this type

(&Tx) prepare_context

XuAPI
pub fn (t &Tx) prepare_context(ctx &context.Context, query string) Stmt

Purpose

Operation on &Tx: prepare context. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
query string
query (string)

Returns

Stmt — a value of this type

(&Tx) stmt

XuAPI
pub fn (t &Tx) stmt(s &Stmt) Stmt

Purpose

Execute stmt on &Tx. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
s &Stmt
s (read-only borrow; caller keeps the original; type &Stmt)

Returns

Stmt — a value of this type

(&Tx) stmt_context

XuAPI
pub fn (t &Tx) stmt_context(ctx &context.Context, s &Stmt) Stmt

Purpose

Operation on &Tx: stmt context. Throws on failure; handle the error or propagate it to the caller.

Parameters

t &Tx
The Tx instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
s &Stmt
s (read-only borrow; caller keeps the original; type &Stmt)

Returns

Stmt — a value of this type

($&Tx) commit

XuAPI
pub fn (t $&Tx) commit() int

Purpose

Execute commit on $&Tx. Throws on failure; handle the error or propagate it to the caller.

Parameters

t $&Tx
The Tx instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Tx) rollback

XuAPI
pub fn (t $&Tx) rollback() int

Purpose

Execute rollback on $&Tx. Throws on failure; handle the error or propagate it to the caller.

Parameters

t $&Tx
The Tx instance used by this call (exclusive borrow).

Returns

int — a value of this type

(&Stmt) exec

XuAPI
pub fn (s &Stmt) exec(args <-> temp) Result

Purpose

Execute SQL statement or service command and return result. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Stmt
The Stmt instance used by this call (borrow).
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Result — a value of this type

(&Stmt) exec_context

XuAPI
pub fn (s &Stmt) exec_context(ctx &context.Context, args <-> temp) Result

Purpose

Operation on &Stmt: exec context. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Stmt
The Stmt instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Result — a value of this type

(&Stmt) query

XuAPI
pub fn (s &Stmt) query(args <-> temp) Rows

Purpose

Execute query on &Stmt. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Stmt
The Stmt instance used by this call (borrow).
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Rows — a value of this type

(&Stmt) query_context

XuAPI
pub fn (s &Stmt) query_context(ctx &context.Context, args <-> temp) Rows

Purpose

Operation on &Stmt: query context. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Stmt
The Stmt instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Rows — a value of this type

(&Stmt) query_row

XuAPI
pub fn (s &Stmt) query_row(args <-> temp) Row

Purpose

Operation on &Stmt: query row.

Parameters

s &Stmt
The Stmt instance used by this call (borrow).
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Row — a value of this type

(&Stmt) query_row_context

XuAPI
pub fn (s &Stmt) query_row_context(ctx &context.Context, args <-> temp) Row

Purpose

Operation on &Stmt: query row context.

Parameters

s &Stmt
The Stmt instance used by this call (borrow).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
args <-> temp
variadic temp (seen inside the function as []temp)

Returns

Row — a value of this type

($&Stmt) close

XuAPI
pub fn (s $&Stmt) close()

Purpose

Operation on $&Stmt: close the resource.

Parameters

s $&Stmt
The Stmt instance used by this call (exclusive borrow).

Returns

This call does not return a value.