Documentation
¶
Overview ¶
Package driver provides file SQL driver implementation. This package implements database/sql/driver interfaces to enable reading CSV, TSV, and LTSV files as SQL databases through SQLite3.
Package driver provides file SQL driver implementation for database/sql.
This package implements a database/sql driver that allows querying CSV, TSV, and LTSV files (including compressed versions) as if they were SQL tables. Files are loaded into an in-memory SQLite database for query execution.
Key features:
- Support for CSV, TSV, and LTSV file formats
- Support for compressed files (gzip, bzip2, xz, zstd)
- Duplicate table name validation across multiple files
- Directory scanning with automatic file discovery
- Table export functionality
Usage:
import _ "github.com/nao1215/filesql/driver"
db, err := sql.Open("filesql", "data.csv")
Index ¶
- Variables
- type Connection
- func (conn *Connection) Begin() (driver.Tx, error)
- func (conn *Connection) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (conn *Connection) Close() error
- func (conn *Connection) Dump(outputDir string) error
- func (conn *Connection) Prepare(query string) (driver.Stmt, error)
- func (conn *Connection) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- type Connector
- type Driver
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoPathsProvided is returned when no paths are provided ErrNoPathsProvided = errors.New("filesql driver: no paths provided") // ErrNoFilesLoaded is returned when no files were loaded ErrNoFilesLoaded = errors.New("filesql driver: no files were loaded") // ErrStmtExecContextNotSupported is returned when statement does not support ExecContext ErrStmtExecContextNotSupported = errors.New("filesql driver: statement does not support ExecContext") // ErrBeginTxNotSupported is returned when underlying connection does not support BeginTx ErrBeginTxNotSupported = errors.New("filesql driver: underlying connection does not support BeginTx") // ErrPrepareContextNotSupported is returned when underlying connection does not support PrepareContext ErrPrepareContextNotSupported = errors.New("filesql driver: underlying connection does not support PrepareContext") // ErrNotFilesqlConnection is returned when connection is not a filesql connection ErrNotFilesqlConnection = errors.New("filesql driver: connection is not a filesql connection") // ErrDuplicateColumnName is returned when a file contains duplicate column names ErrDuplicateColumnName = errors.New("filesql driver: duplicate column name") // ErrDuplicateTableName is returned when multiple files would create the same table name ErrDuplicateTableName = errors.New("filesql driver: duplicate table name") )
Predefined errors
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection implements database/sql/driver.Conn interface. It wraps an underlying SQLite connection that contains loaded file data.
func (*Connection) Begin ¶
func (conn *Connection) Begin() (driver.Tx, error)
Begin implements driver.Conn interface (deprecated, use BeginTx instead)
func (*Connection) Close ¶
func (conn *Connection) Close() error
Close implements driver.Conn interface
func (*Connection) Dump ¶
func (conn *Connection) Dump(outputDir string) error
Dump exports all tables from SQLite3 database to specified directory in CSV format
func (*Connection) Prepare ¶
func (conn *Connection) Prepare(query string) (driver.Stmt, error)
Prepare implements driver.Conn interface (deprecated, use PrepareContext instead)
func (*Connection) PrepareContext ¶
PrepareContext implements driver.ConnPrepareContext interface
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector implements database/sql/driver.Connector interface. It holds connection parameters and manages the creation of database connections. The dsn field contains file paths separated by semicolons for multiple files.
type Driver ¶
type Driver struct{}
Driver implements database/sql/driver.Driver interface for file-based SQL. It serves as the entry point for creating connections to file-based databases.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction implements database/sql/driver.Tx interface. It wraps an underlying SQLite transaction for atomic operations.
func (*Transaction) Commit ¶
func (t *Transaction) Commit() error
Commit implements driver.Tx interface
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
Rollback implements driver.Tx interface