csv

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 11 Imported by: 0

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.

https://sqlite.org/csv.html

Example
db, err := sqlite3.Open(":memory:")
if err != nil {
	log.Fatal(err)
}
defer db.Close()

csv.Register(db)

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)

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

func RegisterFS(db *sqlite3.Conn, fsys fs.FS)

RegisterFS registers the CSV virtual table. If a filename is specified, fsys is used to open the file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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