sqldatabase

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownDialect = fmt.Errorf("unknown dialect")

	ErrTableNotFound = fmt.Errorf("table not found")
	ErrInvalidResult = fmt.Errorf("invalid result")
)

Functions

func RegisterEngine

func RegisterEngine(name string, engineFunc EngineFunc)

Types

type Engine

type Engine interface {
	// Dialect returns the dialect(e.g. mysql, sqlite, postgre) of the database.
	Dialect() string

	// Query executes the query and returns the columns and results.
	Query(ctx context.Context, query string, args ...any) (cols []string, results [][]string, err error)

	// TableNames returns all the table names of the database.
	TableNames(ctx context.Context) ([]string, error)

	// TableInfo returns the table information of the database.
	// Typically, it returns the CREATE TABLE statement.
	TableInfo(ctx context.Context, tables string) (string, error)

	// Close closes the database.
	Close() error
}

Engine is the interface that wraps the database.

type EngineFunc

type EngineFunc func(string) (Engine, error)

EngineFunc is the function that returns the database engine.

type SQLDatabase

type SQLDatabase struct {
	Engine           Engine // The database engine.
	SampleRowsNumber int    // The number of sample rows to show. 0 means no sample rows.
	// contains filtered or unexported fields
}

SQLDatabase sql wrapper.

func NewSQLDatabase

func NewSQLDatabase(engine Engine, ignoreTables map[string]struct{}) (*SQLDatabase, error)

NewSQLDatabase creates a new SQLDatabase.

func NewSQLDatabaseWithDSN

func NewSQLDatabaseWithDSN(dialect, dsn string, ignoreTables map[string]struct{}) (*SQLDatabase, error)

NewSQLDatabaseWithDSN creates a new SQLDatabase with the data source name.

func (*SQLDatabase) Close

func (sd *SQLDatabase) Close() error

Close closes the database.

func (*SQLDatabase) Dialect

func (sd *SQLDatabase) Dialect() string

Dialect returns the dialect(e.g. mysql, sqlite, postgre) of the database.

func (*SQLDatabase) Query

func (sd *SQLDatabase) Query(ctx context.Context, query string) (string, error)

Query executes the query and returns the string that contains columns and results.

func (*SQLDatabase) TableInfo

func (sd *SQLDatabase) TableInfo(ctx context.Context, tables []string) (string, error)

TableInfo returns the table information string of the database. If tables is empty, it will return all the tables, otherwise it will return the given tables.

func (*SQLDatabase) TableNames

func (sd *SQLDatabase) TableNames() []string

TableNames returns all the table names of the database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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