Beispiel #1
0
func main() {
	db, err := ql.OpenMem()
	if err != nil {
		panic(err)
	}
	_, _, err = db.Run(ql.NewRWCtx(), `
        BEGIN TRANSACTION;
        CREATE TABLE data (t time, h uint, bps float);
        COMMIT;
        `)
	if err != nil {
		panic(err)
	}
	for _, date := range listDates() {
		addToDB(date, db)
	}
	rss, _, err := db.Run(ql.NewRWCtx(), "SELECT h, min(bps),avg(bps),max(bps), count(t) FROM data GROUP BY h;")
	if err != nil {
		panic(err)
	}

	for _, rs := range rss {
		if err := rs.Do(false, func(data []interface{}) (bool, error) {
			fmt.Printf("hour %2d, min %4.1f, avg %4.1f, max %4.1f, count %3d\n", data[0], data[1], data[2], data[3], data[4])
			return true, nil
		}); err != nil {
			panic(err)
		}
		fmt.Println("----")
	}
}
Beispiel #2
0
func main() {

	if "" != *flagDbName {
		db, err = ql.OpenFile(*flagDbName, &ql.Options{CanCreate: true})
	} else {
		db, err = ql.OpenMem()
	}
	if nil != err {
		log.Fatalln(err.Error())
	}
	defer db.Close()

	basedir := ""
	if basedir = os.Getenv("GOPATH"); basedir != "" {
		basedir += "/src/github.com/mdlayher/goat/res/ql/"
	}
	files, err := filepath.Glob(basedir + "*.ql")
	if nil != err {
		log.Fatalln(err.Error())
	}

	ctx := ql.NewRWCtx()
	for _, file := range files {
		fmt.Println("Reading", file)
		q, err := ioutil.ReadFile(file)
		if nil != err {
			log.Panicln(err.Error())
		}
		if _, _, err = db.Run(ctx, string(q)); nil != err {
			log.Panicln(err.Error())
		}
	}

	info, err := db.Info()
	fmt.Printf("%#v Error=%s\n", info, err)
}
Beispiel #3
0
func OpenMemDB() error {
	var err error
	DB, err = ql.OpenMem()
	return err
}