dialect

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DbDriver

type DbDriver string

数据库类型。如"postgres"。

const (
	PostgreSQL DbDriver = "postgres"
	MySQL      DbDriver = "mysql"
)

type Driver

type Driver interface {
	ExecQuerier
	// Tx 启动并返回一个新事务。
	// 在事务提交或回滚之前,将使用所提供的上下文
	Tx(context.Context) (Tx, error)
	// Close 关闭数据库连接。
	Close() error
	// Dialect 返回数据库的驱动
	Dialect() DbDriver
}

type ExecQuerier

type ExecQuerier interface {
	// Exec 执行不返回记录的查询。例如,SQL中INSERT或UPDATE。
	// 它将结果扫描到指针v中,对于SQL驱动程序,它是sql.Rows,
	// v 可以是nil,或者是*sql.Result,如果是nil,将忽略结果。
	Exec(ctx context.Context, query string, args []any, v any) error
	// Query 执行返回记录的查询,通常是SQL中的SELECT,
	// 或者有RETURNING子句的INSERT/UPDATE。
	// 它将结果扫描到指针v中,对于SQL驱动程序,它是sql.Result。
	Query(ctx context.Context, query string, args []any, v *Rows) error
}

type Rows

type Rows struct{ RowsScanner }

Rows 包装了sql.Rows,以避免locks copy。 sql.Rows 对象包含对数据库连接的引用以及用于迭代结果集的内部状态。 因此,复制 sql.Rows 对象(例如,将其作为值传递给函数)可能会导致不可预测的行为, 因为复制可能会导致对内部状态和数据库连接的多个引用。

type RowsScanner

type RowsScanner interface {
	Close() error
	ColumnTypes() ([]*sql.ColumnType, error)
	Columns() ([]string, error)
	Err() error
	Next() bool
	NextResultSet() bool
	Scan(dest ...any) error
}

RowScanner 封装了sql.Row的标准方法,用于扫描数据库行。

type Tx

type Tx interface {
	ExecQuerier
	driver.Tx
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL