hep: go-hep.org/x/hep/groot/rsql/rsqldrv Index | Examples | Files

package rsqldrv

import "go-hep.org/x/hep/groot/rsql/rsqldrv"

Package rsqldrv registers a database/sql/driver.Driver implementation for ROOT files.

Index

Examples

Package Files

connector.go driver.go expr.go types.go

func Connector Uses

func Connector(file *riofs.File) driver.Connector

Connector returns a database/sql/driver.Connector from a ROOT file.

Connector can be used to open a database/sql.DB from an already open ROOT file.

func Create Uses

func Create(name string) (*sql.DB, error)

Create is a ROOT/SQL-driver helper function for sql.Open.

It creates a new ROOT file, connected via the ROOT/SQL driver.

func Open Uses

func Open(name string) (*sql.DB, error)

Open is a ROOT/SQL-driver helper function for sql.Open.

It opens a database connection to the ROOT/SQL driver.

Code:

db, err := sql.Open("root", "../../testdata/simple.root")
if err != nil {
    log.Fatal(err)
}
defer db.Close()

rows, err := db.Query("SELECT * FROM tree")
if err != nil {
    log.Fatal(err)
}
defer rows.Close()

type data struct {
    i32 int32
    f32 float32
    str string
}

n := 0
for rows.Next() {
    var v data
    err := rows.Scan(&v.i32, &v.f32, &v.str)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("row[%d]: (%v, %v, %q)\n", n, v.i32, v.f32, v.str)
    n++
}

Output:

row[0]: (1, 1.1, "uno")
row[1]: (2, 2.2, "dos")
row[2]: (3, 3.3, "tres")
row[3]: (4, 4.4, "quatro")

Code:

f, err := groot.Open("../../testdata/simple.root")
if err != nil {
    log.Fatal(err)
}
defer f.Close()

o, err := f.Get("tree")
if err != nil {
    log.Fatal(err)
}

tree := o.(rtree.Tree)

db := sql.OpenDB(rsqldrv.Connector(rtree.FileOf(tree)))
defer db.Close()

rows, err := db.Query("SELECT * FROM tree")
if err != nil {
    log.Fatal(err)
}
defer rows.Close()

type data struct {
    i32 int32
    f32 float32
    str string
}

n := 0
for rows.Next() {
    var v data
    err = rows.Scan(&v.i32, &v.f32, &v.str)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("row[%d]: (%v, %v, %q)\n", n, v.i32, v.f32, v.str)
    n++
}

Output:

row[0]: (1, 1.1, "uno")
row[1]: (2, 2.2, "dos")
row[2]: (3, 3.3, "tres")
row[3]: (4, 4.4, "quatro")

Code:

db, err := sql.Open("root", "../../testdata/simple.root")
if err != nil {
    log.Fatal(err)
}
defer db.Close()

rows, err := db.Query("SELECT (one, two, three) FROM tree")
if err != nil {
    log.Fatal(err)
}
defer rows.Close()

type data struct {
    i32 int32
    f32 float32
    str string
}

n := 0
for rows.Next() {
    var v data
    err := rows.Scan(&v.i32, &v.f32, &v.str)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("row[%d]: (%v, %v, %q)\n", n, v.i32, v.f32, v.str)
    n++
}

Output:

row[0]: (1, 1.1, "uno")
row[1]: (2, 2.2, "dos")
row[2]: (3, 3.3, "tres")
row[3]: (4, 4.4, "quatro")

Code:

db, err := sql.Open("root", "../../testdata/simple.root")
if err != nil {
    log.Fatal(err)
}
defer db.Close()

rows, err := db.Query("SELECT (one, two, three) FROM tree WHERE (one>2 && two < 5)")
if err != nil {
    log.Fatal(err)
}
defer rows.Close()

type data struct {
    i32 int32
    f32 float32
    str string
}

n := 0
for rows.Next() {
    var v data
    err := rows.Scan(&v.i32, &v.f32, &v.str)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("row[%d]: (%v, %v, %q)\n", n, v.i32, v.f32, v.str)
    n++
}

Output:

row[0]: (3, 3.3, "tres")
row[1]: (4, 4.4, "quatro")

func OpenDB Uses

func OpenDB(file *riofs.File) *sql.DB

OpenDB opens a database/sql.DB from an already open ROOT file.

Package rsqldrv imports 14 packages (graph) and is imported by 1 packages. Updated 2019-05-31. Refresh now. Tools for package owners.