Documentation ¶
Overview ¶
Package sqldb provides an SQL database abstraction for performing queries and interacting with the database.
Index ¶
- func CleanQuery(query string) string
- type CockroachDB
- type CockroachDBOptions
- type Engine
- type MariaDB
- type MariaDBOptions
- type MySQL
- func (e *MySQL) Close() error
- func (e *MySQL) Dialect() string
- func (e *MySQL) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (e MySQL) Inspect(ctx context.Context, name string, opts *schema.InspectOptions) (map[string]string, error)
- func (e *MySQL) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (e *MySQL) QueryRow(ctx context.Context, query string, args ...any) *sql.Row
- func (e *MySQL) SampleRowsQuery(table string, k uint) string
- type MySQLOptions
- type Parser
- type Postgres
- func (e *Postgres) Close() error
- func (e *Postgres) Dialect() string
- func (e *Postgres) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (e Postgres) Inspect(ctx context.Context, name string, opts *schema.InspectOptions) (map[string]string, error)
- func (e *Postgres) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (e *Postgres) QueryRow(ctx context.Context, query string, args ...any) *sql.Row
- func (e *Postgres) SampleRowsQuery(table string, k uint) string
- type PostgresOptions
- type QueryResult
- type SQLDB
- type SQLDBOptions
- type SQLite3
- func (e *SQLite3) Close() error
- func (e *SQLite3) Dialect() string
- func (e *SQLite3) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (e SQLite3) Inspect(ctx context.Context, name string, opts *schema.InspectOptions) (map[string]string, error)
- func (e *SQLite3) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (e *SQLite3) QueryRow(ctx context.Context, query string, args ...any) *sql.Row
- func (e *SQLite3) SampleRowsQuery(table string, k uint) string
- type SQLite3Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanQuery ¶ added in v0.0.54
CleanQuery cleans sql query from double white space, comments and leading/trailing spaces.
Types ¶
type CockroachDB ¶
type CockroachDB struct {
*Postgres
}
CockroachDB represents the CockroachDB database engine.
func NewCockroachDB ¶
func NewCockroachDB(dataSourceName string, optFns ...func(o *CockroachDBOptions)) (*CockroachDB, error)
NewCockroachDB creates a new instance of the CockroachDB database engine.
func (*CockroachDB) Dialect ¶
func (e *CockroachDB) Dialect() string
Dialect returns the dialect of the CockroachDB database engine.
type CockroachDBOptions ¶
type CockroachDBOptions struct {
DriverName string
}
CockroachDBOptions holds options for the CockroachDB database engine.
type Engine ¶
type Engine interface { // Dialect returns the dialect of the SQL database engine. Dialect() string // SampleRowsQuery returns the query to retrieve a sample of rows from the specified table (table) with a limit of (k) rows. SampleRowsQuery(table string, k uint) string // Inspect retrieves information about the database schema with the specified name (name) and options (opts). // The returned map contains table names as keys and their corresponding CREATE TABLE statements as values. Inspect(ctx context.Context, name string, opts *schema.InspectOptions) (map[string]string, error) // Exec executes an SQL query with the provided query string and arguments (args), returning the result and any errors encountered. Exec(ctx context.Context, query string, args ...any) (sql.Result, error) // Query executes an SQL query with the provided query string and arguments (args), returning the rows and any errors encountered. Query(ctx context.Context, query string, args ...any) (*sql.Rows, error) // QueryRow executes an SQL query with the provided query string and arguments (args), returning a single row and any errors encountered. QueryRow(ctx context.Context, query string, args ...any) *sql.Row // Close closes the database connection. Close() error }
Engine defines the interface for an SQL database engine.
type MariaDB ¶
type MariaDB struct {
*MySQL
}
MariaDB represents the MariaDB database engine.
func NewMariaDB ¶
func NewMariaDB(dataSourceName string, optFns ...func(o *MariaDBOptions)) (*MariaDB, error)
NewMariaDB creates a new instance of the MariaDB database engine.
type MariaDBOptions ¶
type MariaDBOptions struct {
DriverName string
}
MariaDBOptions holds options for the MariaDB database engine.
type MySQL ¶
type MySQL struct {
// contains filtered or unexported fields
}
MySQL represents the MySQL database engine.
func NewMySQL ¶
func NewMySQL(dataSourceName string, optFns ...func(o *MySQLOptions)) (*MySQL, error)
NewMySQL creates a new instance of the MySQL database engine.
func (*MySQL) Exec ¶
Exec executes an SQL query with the provided query string and arguments (args), returning the result and any errors encountered.
func (MySQL) Inspect ¶
func (e MySQL) Inspect(ctx context.Context, name string, opts *schema.InspectOptions) (map[string]string, error)
Inspect retrieves information about the schema.
func (*MySQL) Query ¶
Query executes an SQL query with the provided query string and arguments (args), returning the rows and any errors encountered.
type MySQLOptions ¶
type MySQLOptions struct {
DriverName string
}
MySQLOptions holds options for the MySQL database engine.
type Parser ¶ added in v0.0.54
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) TableNames ¶ added in v0.0.54
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
Postgres represents the Postgres database engine.
func NewPostgres ¶
func NewPostgres(dataSourceName string, optFns ...func(o *PostgresOptions)) (*Postgres, error)
NewPostgres creates a new instance of the Postgres database engine.
func (*Postgres) Exec ¶
Exec executes an SQL query with the provided query string and arguments (args), returning the result and any errors encountered.
func (Postgres) Inspect ¶
func (e Postgres) Inspect(ctx context.Context, name string, opts *schema.InspectOptions) (map[string]string, error)
Inspect retrieves information about the schema.
func (*Postgres) Query ¶
Query executes an SQL query with the provided query string and arguments (args), returning the rows and any errors encountered.
type PostgresOptions ¶
type PostgresOptions struct {
DriverName string
}
PostgresOptions holds options for the Postgres database engine.
type QueryResult ¶
QueryResult holds the result of an SQL query.
func (*QueryResult) String ¶
func (qr *QueryResult) String() string
String returns the string representation of the QueryResult.
type SQLDB ¶
type SQLDB struct {
// contains filtered or unexported fields
}
SQLDB represents an SQL database.
func New ¶
func New(engine Engine, optFns ...func(o *SQLDBOptions)) (*SQLDB, error)
New creates a new SQLDB instance.
type SQLDBOptions ¶
type SQLDBOptions struct { Schema string Tables []string Exclude []string SampleRowsinTableInfo uint }
SQLDBOptions holds options for the SQLDB.
type SQLite3 ¶
type SQLite3 struct {
// contains filtered or unexported fields
}
SQLite3 represents the SQLite3 database engine.
func NewSQLite3 ¶
func NewSQLite3(dataSourceName string, optFns ...func(o *SQLite3Options)) (*SQLite3, error)
NewSQLite3 creates a new instance of the SQLite3 database engine.
func (*SQLite3) Exec ¶
Exec executes an SQL query with the provided query string and arguments (args), returning the result and any errors encountered.
func (SQLite3) Inspect ¶
func (e SQLite3) Inspect(ctx context.Context, name string, opts *schema.InspectOptions) (map[string]string, error)
Inspect retrieves information about the schema.
func (*SQLite3) Query ¶
Query executes an SQL query with the provided query string and arguments (args), returning the rows and any errors encountered.
type SQLite3Options ¶
type SQLite3Options struct {
DriverName string
}
SQLite3Options holds options for the SQLite3 database engine.