Documentation ¶
Overview ¶
Package rsqldrv registers a database/sql/driver.Driver implementation for ROOT files.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func 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 ¶
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 ¶
Open is a ROOT/SQL-driver helper function for sql.Open.
It opens a database connection to the ROOT/SQL driver.
Example ¶
package main import ( "database/sql" "fmt" "log" ) func main() { 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")
Example (Connector) ¶
package main import ( "database/sql" "fmt" "log" "go-hep.org/x/hep/groot" "go-hep.org/x/hep/groot/rsql/rsqldrv" "go-hep.org/x/hep/groot/rtree" ) func main() { 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")
Example (Tuple) ¶
package main import ( "database/sql" "fmt" "log" ) func main() { 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")
Example (WhereStmt) ¶
package main import ( "database/sql" "fmt" "log" ) func main() { 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")
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.