// Configure funciton opens a SQLite3 connection. func Configure() error { var err error a, b, c := lite.Version() log.Println("SQLite3 Driver version: ", a, b, c) Current, err = sqlx.Open("sqlite3", config.DatabasePath) if err != nil { return err } return nil }
func main() { showVersionFlag := flag.Bool("version", false, "Show version") createFlag := flag.Bool("create", false, "Create DB table") listFlag := flag.Bool("list", false, "List DB entries") addValueFlag := flag.Int("addValue", -1, "Add a value into database") setNameFlag := flag.String("name", "", "Set name to value") flag.Parse() if *showVersionFlag == true { libVersion, _, _ := sqlite.Version() fmt.Println("Using sqlite", libVersion) return } db, err := sql.Open("sqlite3", "db.sqlite") check(err) defer db.Close() if true == *createFlag { initdb(db) } if -1 != *addValueFlag { if "" != *setNameFlag { _, err := db.Exec("INSERT INTO a(a, name) VALUES (?, ?);", *addValueFlag, *setNameFlag) check(err) } else { _, err := db.Exec("INSERT INTO a(a) VALUES (?);", *addValueFlag) check(err) } } if true == *listFlag { rows, err := db.Query("SELECT a, name FROM a;") check(err) // dump values for rows.Next() { var a int64 var name string err = rows.Scan(&a, &name) check(err) fmt.Printf("%d: %s\n", a, name) } } }