const LEVEL_DEFAULT
pub const LEVEL_DEFAULT = 0用途
默认事务隔离级别,沿用底层数据库驱动或服务端的默认隔离配置。
#database/sql使用 database/sql 配合具体驱动管理连接池并执行 SQL。
open 接收驱动对象与该驱动解释的 DSN,首次操作时才打开连接。此例使用 SQLite 内存数据库,处理操作错误,并显式关闭连接池。
前提:准备官方 packages 源码,并为目标平台构建 SQLite 原生桥。在工程的 xu.xun 中加入以下依赖,将路径替换为该源码目录:
require:
"github.com/xulang-org/packages": file:/path/to/packages
服务端驱动与 DSN 参见 MySQL 快速示例;此处 MySQL 服务集成:待验。
将完整程序保存为 main.xu,用 xu check main.xu 检查。原生静态库的一步链接支持 macOS arm64/x64,可在这些目标上使用 xu run main.xu;Linux 需要输出对象文件后另行链接。此例已通过 SDK 检查;原生执行:待验。
@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
}预期输出:1(插入行数)。
以下源码来自官方 examples 仓库,可复制或下载。请在完整工程中使用本地 Xu SDK 运行;网络、数据库和桌面示例需要对应的服务或资源。
18_database_mysql/main.xu@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@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
}const LEVEL_DEFAULTpub const LEVEL_DEFAULT = 0默认事务隔离级别,沿用底层数据库驱动或服务端的默认隔离配置。
const LEVEL_READ_UNCOMMITTEDpub const LEVEL_READ_UNCOMMITTED = 1读未提交(Read Uncommitted)事务隔离级别,允许读取其他并发事务未提交的数据变更(脏读)。
const LEVEL_READ_COMMITTEDpub const LEVEL_READ_COMMITTED = 2读已提交(Read Committed)事务隔离级别,仅允许读取已提交数据,避免脏读。
const LEVEL_WRITE_COMMITTEDpub const LEVEL_WRITE_COMMITTED = 3常量 LEVEL_WRITE_COMMITTED,定义了相关的协议或算法配置参数。
const LEVEL_REPEATABLE_READpub const LEVEL_REPEATABLE_READ = 4可重复读(Repeatable Read)事务隔离级别,保证同一事务内多次读取相同行数据一致,避免不可重复读。
const LEVEL_SNAPSHOTpub const LEVEL_SNAPSHOT = 5常量 LEVEL_SNAPSHOT,定义了相关的协议或算法配置参数。
const LEVEL_SERIALIZABLEpub const LEVEL_SERIALIZABLE = 6串行化(Serializable)事务隔离级别;具体支持情况由驱动与数据库决定。
const LEVEL_LINEARIZABLEpub const LEVEL_LINEARIZABLE = 7常量 LEVEL_LINEARIZABLE,定义了相关的协议或算法配置参数。
struct TxOptionspub struct TxOptions {
pub isolation int
pub read_only bool
}Sql 配置参数与选项集合。
isolation intread_only boolstruct NamedArgpub struct NamedArg {
pub name string
pub value temp
}承载 name、value 等属性的结构体。
name stringvalue tempstruct DBStatspub 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
}承载 max_open_connections、open_connections、in_use、idle、wait_count 等属性的结构体。
max_open_connections intopen_connections intin_use intidle intwait_count intmax_idle_closed intmax_idle_time_closed intmax_lifetime_closed intstruct DBpub 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
}并发安全的数据库连接池对象,管理空闲连接、连接生命周期与事务分发。
drv driver.Driverdsn stringuse_connector intopener chan ConnSlotidle chan PooledConnst chan PoolStatestruct Connpub 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
}承载 closed、slot、created_ns、idle_ns、idle 等属性的结构体。
closed intslot chan PooledConncreated_ns intidle_ns intidle chan PooledConnpst chan PoolStatedrv driver.Driverdsn stringuse_connector intopener chan ConnSlotstruct Txpub 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
}在单个专用数据库连接上执行的在建事务,须以 commit 或 rollback 显式结束。
slot chan PooledConndtx driver.Txdone intfrom_pool intcreated_ns intidle_ns intidle chan PooledConnpst chan PoolStatedrv driver.Driverdsn stringuse_connector intopener chan ConnSlotstruct Resultpub struct Result {
pub last_insert_id int
pub rows_affected int
}承载 last_insert_id、rows_affected 等属性的结构体。
last_insert_id introws_affected intstruct NullInt64pub struct NullInt64 {
pub v int
pub valid bool
}承载 v、valid 等属性的结构体。
v intvalid boolstruct NullStringpub struct NullString {
pub s string
pub valid bool
}承载 s、valid 等属性的结构体。
s stringvalid boolstruct NullBoolpub struct NullBool {
pub v bool
pub valid bool
}承载 v、valid 等属性的结构体。
v boolvalid boolstruct NullFloat64pub struct NullFloat64 {
pub v f64
pub valid bool
}承载 v、valid 等属性的结构体。
v f64valid boolstruct NullInt32pub struct NullInt32 {
pub v i32
pub valid bool
}承载 v、valid 等属性的结构体。
v i32valid boolstruct NullBytepub struct NullByte {
pub v u8
pub valid bool
}承载 v、valid 等属性的结构体。
v u8valid boolstruct NullTimepub struct NullTime {
pub t time.Time
pub valid bool
}承载 t、valid 等属性的结构体。
t time.Timevalid boolstruct ColumnTypepub 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
}承载 col、db_type、length、length_ok、nullable 等属性的结构体。
col stringdb_type stringlength intlength_ok boolnullable boolnullable_ok boolprecision intscale intprecision_ok boolstruct Rowspub 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
}SQL 查询结果迭代器游标,按行遍历扫描数据列,使用完毕须调用 close 释放。
cols []stringcells []stringcur []stringncols inti intclosed interr stringhas intpooled intidle chan PooledConnpst chan PoolStatestruct Rowpub struct Row {
pub cells []string
pub err string
}承载 cells、err 等属性的结构体。
cells []stringerr stringstruct Stmtpub 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
}承载 ds、qtext、closed、from_db、created_ns 等属性的结构体。
ds driver.Stmtqtext stringclosed intfrom_db intcreated_ns intidle_ns intidle chan PooledConnpst chan PoolStatedrv driver.Driverdsn stringuse_connector intopener chan ConnSlotnamedpub fn named(name string, value temp) NamedArg构造包含键名与键值的命名 SQL 参数(NamedArg)。
name stringvalue tempNamedArg — 该类型的值
openpub fn open(d driver.Driver, name string) DB使用驱动对象与数据源连接串(DSN)创建数据库连接池 DB;首次操作时才打开连接。
d driver.Drivername string数据库连接池实例 DB
open_dbpub fn open_db(c driver.Connector) DB执行 open db 操作。
c driver.ConnectorDB — 该类型的值
open_db_contextpub fn open_db_context(ctx &context.Context, c driver.Connector) DB执行 open db context 操作。失败时抛出错误,调用方需处理或继续传播。
ctx &context.Contextc driver.ConnectorDB — 该类型的值
is_no_rowspub fn is_no_rows(e errors.Error) bool判断是否 no rows。
e errors.Errorbool — 是否成立
is_tx_donepub fn is_tx_done(e errors.Error) bool判断是否 tx done。
e errors.Errorbool — 是否成立
is_conn_donepub fn is_conn_done(e errors.Error) bool判断是否 conn done。
e errors.Errorbool — 是否成立
is_bad_connpub fn is_bad_conn(e errors.Error) bool判断是否 bad conn。
e errors.Errorbool — 是否成立
isolation_namepub fn isolation_name(level int) string执行 isolation name 操作。
level intstring — 结果字符串
(&DB) driverpub fn (db &DB) driver() driver.Driver&DB 上的操作:返回该模块提供的数据库驱动实例(实现 database/sql/driver.Driver 接口)。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。driver.Driver — 该类型的值
(&DB) pingpub fn (db &DB) ping() int发送心跳保活探测请求,检测连接活性与服务可用性。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。int — 该类型的值
(&DB) ping_contextpub fn (db &DB) ping_context(ctx &context.Context) int&DB 上的操作:执行 ping context 操作。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextint — 该类型的值
(&DB) execpub fn (db &DB) exec(query string, args <-> temp) Result执行 SQL 语句或服务命令,返回受影响行数或执行结果。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。query stringargs <-> tempResult — 该类型的值
(&DB) exec_contextpub fn (db &DB) exec_context(ctx &context.Context, query string, args <-> temp) Result&DB 上的操作:执行 exec context 操作。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempResult — 该类型的值
(&DB) querypub fn (db &DB) query(query string, args <-> temp) Rows&DB 上的操作:查询串。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。query stringargs <-> tempRows — 该类型的值
(&DB) query_contextpub fn (db &DB) query_context(ctx &context.Context, query string, args <-> temp) Rows&DB 上的操作:查询串上下文。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempRows — 该类型的值
(&DB) query_rowpub fn (db &DB) query_row(query string, args <-> temp) Row&DB 上的操作:执行 query row 操作。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。query stringargs <-> tempRow — 该类型的值
(&DB) query_row_contextpub fn (db &DB) query_row_context(ctx &context.Context, query string, args <-> temp) Row&DB 上的操作:执行 query row context 操作。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempRow — 该类型的值
(&DB) preparepub fn (db &DB) prepare(query string) Stmt在 &DB 上执行 prepare 操作。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。query stringStmt — 该类型的值
(&DB) prepare_contextpub fn (db &DB) prepare_context(ctx &context.Context, query string) Stmt&DB 上的操作:执行 prepare context 操作。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringStmt — 该类型的值
(&DB) beginpub fn (db &DB) begin() Tx在 &DB 上执行 begin 操作。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。Tx — 该类型的值
(&DB) begin_txpub fn (db &DB) begin_tx(ctx &context.Context, opts TxOptions) Tx&DB 上的操作:执行 begin tx 操作。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextopts TxOptionsTx — 该类型的值
(&DB) set_max_open_connspub fn (db &DB) set_max_open_conns(n int)&DB 上的操作:设置 max open conns。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。n int不返回值。
(&DB) set_max_idle_connspub fn (db &DB) set_max_idle_conns(n int)&DB 上的操作:设置 max idle conns。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。n int不返回值。
(&DB) set_conn_max_lifetimepub fn (db &DB) set_conn_max_lifetime(d int)&DB 上的操作:设置 conn max lifetime。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。d int不返回值。
(&DB) set_conn_max_idle_timepub fn (db &DB) set_conn_max_idle_time(d int)&DB 上的操作:设置 conn max idle time。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。d int不返回值。
(&DB) statspub fn (db &DB) stats() DBStats在 &DB 上执行 stats 操作。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。DBStats — 该类型的值
($&DB) closepub fn (db $&DB) close() int$&DB 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。
db $&DBDB 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
(&DB) connpub fn (db &DB) conn(ctx &context.Context) Conn&DB 上的操作:连接。失败时抛出错误,调用方需处理或继续传播。
db &DBDB 实例;以只读借用传入,调用方仍持有实例。ctx &context.ContextConn — 该类型的值
(&Conn) ping_contextpub fn (c &Conn) ping_context(ctx &context.Context) int&Conn 上的操作:执行 ping context 操作。失败时抛出错误,调用方需处理或继续传播。
c &ConnConn 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextint — 该类型的值
(&Conn) exec_contextpub fn (c &Conn) exec_context(ctx &context.Context, query string, args <-> temp) Result&Conn 上的操作:执行 exec context 操作。失败时抛出错误,调用方需处理或继续传播。
c &ConnConn 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempResult — 该类型的值
(&Conn) query_contextpub fn (c &Conn) query_context(ctx &context.Context, query string, args <-> temp) Rows&Conn 上的操作:查询串上下文。失败时抛出错误,调用方需处理或继续传播。
c &ConnConn 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempRows — 该类型的值
(&Conn) query_row_contextpub fn (c &Conn) query_row_context(ctx &context.Context, query string, args <-> temp) Row&Conn 上的操作:执行 query row context 操作。
c &ConnConn 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempRow — 该类型的值
(&Conn) rawpub fn (c &Conn) raw() driver.Conn在 &Conn 上执行 raw 操作。失败时抛出错误,调用方需处理或继续传播。
c &ConnConn 实例;以只读借用传入,调用方仍持有实例。driver.Conn — 该类型的值
(&Conn) prepare_contextpub fn (c &Conn) prepare_context(ctx &context.Context, query string) Stmt&Conn 上的操作:执行 prepare context 操作。失败时抛出错误,调用方需处理或继续传播。
c &ConnConn 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringStmt — 该类型的值
(&Conn) begin_txpub fn (c &Conn) begin_tx(ctx &context.Context, opts TxOptions) Tx&Conn 上的操作:执行 begin tx 操作。失败时抛出错误,调用方需处理或继续传播。
c &ConnConn 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextopts TxOptionsTx — 该类型的值
($&Conn) closepub fn (c $&Conn) close() int$&Conn 上的操作:关闭资源。
c $&ConnConn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
(Result) last_insert_idpub fn (r Result) last_insert_id() intResult 上的操作:执行 last insert id 操作。
r ResultResult 实例;按值接收。int — 该类型的值
(Result) rows_affectedpub fn (r Result) rows_affected() intResult 上的操作:执行 rows affected 操作。
r ResultResult 实例;按值接收。int — 该类型的值
($&Rows) nextpub fn (r $&Rows) next() bool$&Rows 上的操作:取出下一项;没有则按本类型约定结束。
r $&RowsRows 实例;以独占借用传入,方法可修改它,调用方仍持有实例。bool — 是否成立
($&Rows) takepub fn (r $&Rows) take() []temp在 $&Rows 上执行 take 操作。失败时抛出错误,调用方需处理或继续传播。
r $&RowsRows 实例;以独占借用传入,方法可修改它,调用方仍持有实例。[]temp — 切片结果
(&Rows) columnspub fn (r &Rows) columns() []string在 &Rows 上执行 columns 操作。
r &RowsRows 实例;以只读借用传入,调用方仍持有实例。[]string — 切片结果
($&Rows) closepub fn (r $&Rows) close()$&Rows 上的操作:关闭资源。
r $&RowsRows 实例;以独占借用传入,方法可修改它,调用方仍持有实例。不返回值。
(&Rows) errpub fn (r &Rows) err() string在 &Rows 上执行 err 操作。
r &RowsRows 实例;以只读借用传入,调用方仍持有实例。string — 结果字符串
(ColumnType) namepub fn (ct ColumnType) name() stringColumnType 上的操作:名称。
ct ColumnTypeColumnType 实例;按值接收。string — 结果字符串
(ColumnType) database_type_namepub fn (ct ColumnType) database_type_name() stringColumnType 上的操作:执行 database type name 操作。
ct ColumnTypeColumnType 实例;按值接收。string — 结果字符串
(ColumnType) lengthpub fn (ct ColumnType) length() driver.NumberColumnType 上的操作:返回当前长度。
ct ColumnTypeColumnType 实例;按值接收。driver.Number — 该类型的值
(ColumnType) nullablepub fn (ct ColumnType) nullable() driver.NullInfo在 ColumnType 上执行 nullable 操作。
ct ColumnTypeColumnType 实例;按值接收。driver.NullInfo — 该类型的值
(ColumnType) decimal_sizepub fn (ct ColumnType) decimal_size() driver.DecimalSizeColumnType 上的操作:执行 decimal size 操作。
ct ColumnTypeColumnType 实例;按值接收。driver.DecimalSize — 该类型的值
(&Rows) column_typespub fn (r &Rows) column_types() []ColumnType&Rows 上的操作:执行 column types 操作。
r &RowsRows 实例;以只读借用传入,调用方仍持有实例。[]ColumnType — 切片结果
($&Rows) next_result_setpub fn (r $&Rows) next_result_set() bool$&Rows 上的操作:执行 next result set 操作。
r $&RowsRows 实例;以独占借用传入,方法可修改它,调用方仍持有实例。bool — 是否成立
(&Row) errpub fn (r &Row) err() string在 &Row 上执行 err 操作。
r &RowRow 实例;以只读借用传入,调用方仍持有实例。string — 结果字符串
(&Row) takepub fn (r &Row) take() []temp在 &Row 上执行 take 操作。失败时抛出错误,调用方需处理或继续传播。
r &RowRow 实例;以只读借用传入,调用方仍持有实例。[]temp — 切片结果
(&Tx) execpub fn (t &Tx) exec(query string, args <-> temp) Result执行 SQL 语句或服务命令,返回受影响行数或执行结果。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。query stringargs <-> tempResult — 该类型的值
(&Tx) exec_contextpub fn (t &Tx) exec_context(ctx &context.Context, query string, args <-> temp) Result&Tx 上的操作:执行 exec context 操作。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempResult — 该类型的值
(&Tx) querypub fn (t &Tx) query(query string, args <-> temp) Rows&Tx 上的操作:查询串。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。query stringargs <-> tempRows — 该类型的值
(&Tx) query_contextpub fn (t &Tx) query_context(ctx &context.Context, query string, args <-> temp) Rows&Tx 上的操作:查询串上下文。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempRows — 该类型的值
(&Tx) query_rowpub fn (t &Tx) query_row(query string, args <-> temp) Row&Tx 上的操作:执行 query row 操作。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。query stringargs <-> tempRow — 该类型的值
(&Tx) query_row_contextpub fn (t &Tx) query_row_context(ctx &context.Context, query string, args <-> temp) Row&Tx 上的操作:执行 query row context 操作。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringargs <-> tempRow — 该类型的值
(&Tx) preparepub fn (t &Tx) prepare(query string) Stmt在 &Tx 上执行 prepare 操作。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。query stringStmt — 该类型的值
(&Tx) prepare_contextpub fn (t &Tx) prepare_context(ctx &context.Context, query string) Stmt&Tx 上的操作:执行 prepare context 操作。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextquery stringStmt — 该类型的值
(&Tx) stmtpub fn (t &Tx) stmt(s &Stmt) Stmt在 &Tx 上执行 stmt 操作。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。s &StmtStmt — 该类型的值
(&Tx) stmt_contextpub fn (t &Tx) stmt_context(ctx &context.Context, s &Stmt) Stmt&Tx 上的操作:执行 stmt context 操作。失败时抛出错误,调用方需处理或继续传播。
t &TxTx 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contexts &StmtStmt — 该类型的值
($&Tx) commitpub fn (t $&Tx) commit() int在 $&Tx 上执行 commit 操作。失败时抛出错误,调用方需处理或继续传播。
t $&TxTx 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
($&Tx) rollbackpub fn (t $&Tx) rollback() int在 $&Tx 上执行 rollback 操作。失败时抛出错误,调用方需处理或继续传播。
t $&TxTx 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
(&Stmt) execpub fn (s &Stmt) exec(args <-> temp) Result执行 SQL 语句或服务命令,返回受影响行数或执行结果。失败时抛出错误,调用方需处理或继续传播。
s &StmtStmt 实例;以只读借用传入,调用方仍持有实例。args <-> tempResult — 该类型的值
(&Stmt) exec_contextpub fn (s &Stmt) exec_context(ctx &context.Context, args <-> temp) Result&Stmt 上的操作:执行 exec context 操作。失败时抛出错误,调用方需处理或继续传播。
s &StmtStmt 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextargs <-> tempResult — 该类型的值
(&Stmt) querypub fn (s &Stmt) query(args <-> temp) Rows&Stmt 上的操作:查询串。失败时抛出错误,调用方需处理或继续传播。
s &StmtStmt 实例;以只读借用传入,调用方仍持有实例。args <-> tempRows — 该类型的值
(&Stmt) query_contextpub fn (s &Stmt) query_context(ctx &context.Context, args <-> temp) Rows&Stmt 上的操作:查询串上下文。失败时抛出错误,调用方需处理或继续传播。
s &StmtStmt 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextargs <-> tempRows — 该类型的值
(&Stmt) query_rowpub fn (s &Stmt) query_row(args <-> temp) Row&Stmt 上的操作:执行 query row 操作。
s &StmtStmt 实例;以只读借用传入,调用方仍持有实例。args <-> tempRow — 该类型的值
(&Stmt) query_row_contextpub fn (s &Stmt) query_row_context(ctx &context.Context, args <-> temp) Row&Stmt 上的操作:执行 query row context 操作。
s &StmtStmt 实例;以只读借用传入,调用方仍持有实例。ctx &context.Contextargs <-> tempRow — 该类型的值
($&Stmt) closepub fn (s $&Stmt) close()$&Stmt 上的操作:关闭资源。
s $&StmtStmt 实例;以独占借用传入,方法可修改它,调用方仍持有实例。不返回值。