Esempio n. 1
0
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()))
	}
}
Esempio n. 2
0
func Users(t *testing.T, store UsersStore) {
	var first, second vsafe.User
	var users []*vsafe.User
	createUsers(t, store, &first, &second)
	if err := store.Users(nil, consume.AppendPtrsTo(&users, nil)); err != nil {
		t.Fatalf("Got error reading database: %v", err)
	}
	assertUserEqual(t, &second, users[0])
	assertUserEqual(t, &first, users[1])
	if out := len(users); out != 2 {
		t.Errorf("Expected 2, got %d", out)
	}
}
Esempio n. 3
0
// Entries returns a new slice containing entries encrypted with keyId and
// matching query and orders them by Id. It does not decrypt the sensitive
// fields within the fetched entries. query is searched for within url,
// title, and description of each entry ignoring case to determine whether or
// not there is a match. Whitespace within query and entry fields are
// normalized to a single space before matching happens. The empty string
// matches all entries.
func Entries(
	store EntriesByOwnerRunner,
	keyId int64,
	query string) ([]*vsafe.Entry, error) {
	var results []*vsafe.Entry
	if err := store.EntriesByOwner(
		nil,
		keyId,
		functional.FilterConsumer(
			consume.AppendPtrsTo(&results, nil),
			newEntryFilter(query))); err != nil {
		return nil, err
	}
	return results, nil
}
Esempio n. 4
0
func EntriesByOwner(t *testing.T, store EntriesByOwnerStore) {
	var first, second vsafe.Entry
	createEntries(t, store, &first, &second)
	e := vsafe.Entry{Owner: kOwner + 1}
	if err := store.AddEntry(nil, &e); err != nil {
		t.Fatalf("Got error adding entry %v", err)
	}
	var entries []*vsafe.Entry
	if err := store.EntriesByOwner(nil, kOwner, consume.AppendPtrsTo(&entries, nil)); err != nil {
		t.Fatalf("Got error reading database by id: %v", err)
	}
	if len(entries) != 2 {
		t.Fatalf("Expected 2 entries back, got %d", len(entries))
	}
	assertEntryEqual(t, &first, entries[0])
	assertEntryEqual(t, &second, entries[1])
}