database

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package database 提供数据库查询工具

支持 SQL 数据库查询操作。

Index

Constants

View Source
const (
	// DefaultMaxRows 默认最大返回行数,防止 OOM
	DefaultMaxRows = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseTool

type DatabaseTool struct {
	// contains filtered or unexported fields
}

DatabaseTool 数据库工具

func NewDatabaseTool

func NewDatabaseTool(db *sql.DB, opts ...Option) *DatabaseTool

NewDatabaseTool 创建数据库工具

func (*DatabaseTool) Tools

func (t *DatabaseTool) Tools() []tool.Tool

Tools 返回数据库工具集合

type Option

type Option func(*DatabaseTool)

Option 数据库工具选项

func WithMaxRows

func WithMaxRows(maxRows int) Option

WithMaxRows 设置查询最大返回行数(默认 1000,防止 OOM)

func WithReadOnly

func WithReadOnly(readOnly bool) Option

WithReadOnly 设置为只读模式

type QueryInput

type QueryInput struct {
	SQL    string `json:"sql" description:"SQL 查询语句"`
	Params []any  `json:"params,omitempty" description:"查询参数"`
}

QueryInput 查询输入

type QueryOutput

type QueryOutput struct {
	Columns []string `json:"columns"`
	Rows    [][]any  `json:"rows"`
	Count   int      `json:"count"`
}

QueryOutput 查询输出

func QuickQuery

func QuickQuery(ctx context.Context, db *sql.DB, query string, args ...any) (QueryOutput, error)

QuickQuery 快速查询辅助函数

Jump to

Keyboard shortcuts

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