Documentation
¶
Overview ¶
Package csv provides a CSV virtual table.
The CSV virtual table reads RFC 4180 formatted comma-separated values, and returns that content as if it were rows and columns of an SQL table.
Example ¶
db, err := sqlite3.Open(":memory:")
if err != nil {
log.Fatal(err)
}
defer db.Close()
err = csv.Register(db)
if err != nil {
log.Fatal(err)
}
err = db.Exec(`
CREATE VIRTUAL TABLE eurofxref USING csv(
filename = 'testdata/eurofxref.csv',
header = YES,
columns = 42,
)`)
if err != nil {
log.Fatal(err)
}
stmt, _, err := db.Prepare(`SELECT USD FROM eurofxref WHERE Date = '2022-02-22'`)
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
if stmt.Step() {
fmt.Printf("On Twosday, 1€ = $%g", stmt.ColumnFloat(0))
}
if err := stmt.Reset(); err != nil {
log.Fatal(err)
}
err = db.Exec(`DROP TABLE eurofxref`)
if err != nil {
log.Fatal(err)
}
Output: On Twosday, 1€ = $1.1342
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(db *sqlite3.Conn) error
Register registers the CSV virtual table. If a filename is specified, os.Open is used to open the file.
func RegisterFS ¶ added in v0.12.0
RegisterFS registers the CSV virtual table. If a filename is specified, fsys is used to open the file.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.