func main() { flag.Parse() if fDb == "" { fmt.Println("Need to specify -db flag.") flag.Usage() return } conn, err := sqlite.Open(fDb) if err != nil { fmt.Printf("Unable to open database - %s\n", fDb) return } dbase := sqlite_db.New(conn) defer dbase.Close() store := for_sqlite.New(dbase) var users []*vsafe.User if err = store.Users(nil, consume.AppendPtrsTo(&users, nil)); err != nil { fmt.Printf("Error fetching users - %v\n", err) return } usersById := make(map[int64]*vsafe.User) for _, user := range users { usersById[user.Id] = user } for _, user := range users { fmt.Printf("%s\t%s\n", user.Name, ownerStr(usersById, user.GetOwner())) } }
func setupDb(filepath string) { conn, err := sqlite.Open(filepath) if err != nil { panic(err) } dbase := sqlite_db.New(conn) kDoer = sqlite_db.NewDoer(dbase) kStore = for_sqlite.New(dbase) }
func openDb(t *testing.T) *sqlite_db.Db { conn, err := sqlite.Open(":memory:") if err != nil { t.Fatalf("Error opening database: %v", err) } db := sqlite_db.New(conn) err = db.Do(func(conn *sqlite.Conn) error { return sqlite_setup.SetUpTables(conn) }) if err != nil { t.Fatalf("Error creating tables: %v", err) } return db }
func main() { flag.Parse() if fDb == "" || fName == "" || fPassword == "" { fmt.Println("Need to specify -db, -name, and -password flag.") flag.Usage() return } conn, err := sqlite.Open(fDb) if err != nil { fmt.Printf("Unable to open database - %s\n", fDb) return } dbase := sqlite_db.New(conn) defer dbase.Close() err = dbase.Do(func(conn *sqlite.Conn) error { return sqlite_setup.SetUpTables(conn) }) if err != nil { fmt.Printf("Unable to create tables - %v\n", err) return } store := for_sqlite.New(dbase) var user vsafe.User if fMasterName == "" { err = user.Init(fName, fPassword) } else { var master vsafe.User if err = store.UserByName(nil, fMasterName, &master); err != nil { fmt.Printf("Error retrieving master user - %v\n", err) return } var key *vsafe.Key if key, err = master.VerifyPassword(fMasterPassword); err != nil { fmt.Printf("Error verifying master password - %v\n", err) return } err = user.InitWithKey(fName, fPassword, key) } if err != nil { fmt.Printf("Error initializing user - %v\n", err) return } if err = store.AddUser(nil, &user); err != nil { fmt.Printf("Error storing user in database - %v\n", err) return } }
func main() { flag.Parse() if fDb == "" || fName == "" { fmt.Println("Need to specify -db and -name flag.") flag.Usage() return } conn, err := sqlite.Open(fDb) if err != nil { fmt.Printf("Unable to open database - %s\n", fDb) return } dbase := sqlite_db.New(conn) defer dbase.Close() store := for_sqlite.New(dbase) if err = store.RemoveUser(nil, fName); err != nil { fmt.Printf("Error removing user - %v\n", err) return } }
func main() { flag.Parse() if fDb == "" || fName == "" || fPassword == "" { fmt.Println("Need to specify -db, -name, and -password flag.") flag.Usage() return } conn, err := sqlite.Open(fDb) if err != nil { fmt.Printf("Unable to open database - %s\n", fDb) return } dbase := sqlite_db.New(conn) defer dbase.Close() store := for_sqlite.New(dbase) doer := sqlite_db.NewDoer(dbase) var user vsafe.User if err = store.UserByName(nil, fName, &user); err != nil { fmt.Printf("Error retrieving user - %v\n", err) return } var key *vsafe.Key if key, err = user.VerifyPassword(fPassword); err != nil { fmt.Printf("Error verifying user password - %v\n", err) return } decoder := json.NewDecoder(os.Stdin) var entryList []*jsonEntry if err = decoder.Decode(&entryList); err != nil { fmt.Printf("Error decoding json - %v\n", err) return } err = doer.Do(func(t db.Transaction) error { return doImport(t, store, entryList, key) }) if err != nil { fmt.Printf("Import failed - %v\n", err) } }