Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) Dialect ¶
func (sd *SQLDatabase) Dialect() string
Dialect returns the dialect(e.g. mysql, sqlite, postgre) of the database.
func (*SQLDatabase) Query ¶
Query executes the query and returns the string that contains columns and results.
func (*SQLDatabase) TableInfo ¶
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.
Click to show internal directories.
Click to hide internal directories.