Documentation ¶
Overview ¶
Package sql 数据库/数据处理相关工具
Index ¶
- Variables
- func Find[T any](db *Sqlite, table string, condition string, questions ...interface{}) (obj T, err error)
- func FindAll[T any](db *Sqlite, table string, condition string, questions ...interface{}) ([]*T, error)
- func Query[T any](db *Sqlite, q string, args ...interface{}) (obj T, err error)
- func QueryAll[T any](db *Sqlite, q string, questions ...interface{}) ([]*T, error)
- type Sqlite
- func (db *Sqlite) CanFind(table string, condition string, questions ...interface{}) bool
- func (db *Sqlite) CanQuery(q string, questions ...interface{}) bool
- func (db *Sqlite) Close() (err error)
- func (db *Sqlite) Count(table string) (num int, err error)
- func (db *Sqlite) Create(table string, objptr interface{}, additional ...string) (err error)
- func (db *Sqlite) Del(table string, condition string, questions ...interface{}) error
- func (db *Sqlite) Drop(table string) error
- func (db *Sqlite) Find(table string, objptr interface{}, condition string, questions ...interface{}) error
- func (db *Sqlite) FindFor(table string, objptr interface{}, condition string, f func() error, ...) error
- func (db *Sqlite) Insert(table string, objptr interface{}) error
- func (db *Sqlite) InsertUnique(table string, objptr interface{}) error
- func (db *Sqlite) ListTables() (s []string, err error)
- func (db *Sqlite) Open(cachettl time.Duration) (err error)
- func (db *Sqlite) Pick(table string, objptr interface{}, questions ...interface{}) error
- func (db *Sqlite) PickFor(table string, n uint, objptr interface{}, f func() error, ...) error
- func (db *Sqlite) Query(q string, objptr interface{}, args ...interface{}) error
- func (db *Sqlite) QueryFor(q string, objptr interface{}, f func() error, questions ...interface{}) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNilDB = errors.New("sqlite: db is not initialized") ErrNullResult = errors.New("sqlite: null result") DriverName = "sqlite3" )
Functions ¶
func Find ¶ added in v1.6.1
func Find[T any](db *Sqlite, table string, condition string, questions ...interface{}) (obj T, err error)
Find 查询数据库,返回第一条结果. condition 可为"WHERE id = 0". 默认字段与结构体元素顺序一致. 返回错误.
func FindAll ¶ added in v1.6.1
func FindAll[T any](db *Sqlite, table string, condition string, questions ...interface{}) ([]*T, error)
FindAll 查询数据库,返回多个结果. condition 可为"WHERE id = 0". 默认字段与结构体元素顺序一致. 返回错误.
Types ¶
type Sqlite ¶
type Sqlite struct {
// contains filtered or unexported fields
}
Sqlite 数据库对象
func (*Sqlite) CanFind ¶
CanFind 查询数据库是否有 condition. condition 可为"WHERE id = 0". 默认字段与结构体元素顺序一致. 返回错误.
func (*Sqlite) CanQuery ¶ added in v0.5.0
CanQuery 查询数据库是否有 q. q 为一整条查询语句, 慎用. 默认字段与结构体元素顺序一致. 返回错误.
func (*Sqlite) Find ¶
func (db *Sqlite) Find(table string, objptr interface{}, condition string, questions ...interface{}) error
Find 查询数据库,写入第一条结果到 objptr. condition 可为"WHERE id = 0". 默认字段与结构体元素顺序一致. 返回错误.
func (*Sqlite) FindFor ¶
func (db *Sqlite) FindFor(table string, objptr interface{}, condition string, f func() error, questions ...interface{}) error
FindFor 查询数据库,用函数 f 遍历结果. condition 可为"WHERE id = 0". 默认字段与结构体元素顺序一致. 返回错误.
func (*Sqlite) InsertUnique ¶
InsertUnique 插入数据集. 如果 PK 存在会报错. 默认结构体的第一个元素为主键. 返回错误.
func (*Sqlite) ListTables ¶
ListTables 列出所有表名 返回所有表名+错误
func (*Sqlite) PickFor ¶ added in v1.6.1
func (db *Sqlite) PickFor(table string, n uint, objptr interface{}, f func() error, questions ...interface{}) error
PickFor 从 table 随机多行
Click to show internal directories.
Click to hide internal directories.