Ejemplo n.º 1
0
func getDB(name string) *db.Database {
	D, err := db.GetDB(name)
	if err != nil {
		log.Fatalf("Cannot get database '%s': %s\n", name, err)
	}
	return D
}
Ejemplo n.º 2
0
func delette(args []string) {
	id := checkOneArg("delete", args)

	problems, err := db.GetDB("problems")
	if err != nil {
		_errx("Cannot get db 'problems': %s\n", err)
	}
	var P eval.Problem
	rev, err := problems.Get(id, &P)
	if err != nil {
		_errx("Couldn't get problem '%s': %s\n", id, err)
	}

	// Store in 'problems-deleted'
	delproblems, err := db.GetOrCreateDB("problems-deleted")
	if err != nil {
		_errx("Cannot get db 'problems-deleted'")
	}
	salt := db.RandString(8)
	err = delproblems.Put(id+"-"+salt, &P)
	if err != nil {
		_errx("Cannot backup deleted problem '%s': %s\n", id, err)
	}

	// Delete
	err = problems.Delete(id, rev)
	if err != nil {
		_errx("Couldn't delete problem '%s': %s\n", id, err)
	}

	fmt.Printf("Problem '%s' deleted\n", id)
}
Ejemplo n.º 3
0
func list(args []string) {
	problems, err := db.GetDB("problems")
	if err != nil {
		_errx("Cannot get db 'problems': %s\n", err)
	}

	ids, err := problems.AllIDs()
	if err != nil {
		_errx("Cannot get all IDs from 'problems'")
	}
	for _, id := range ids {
		fmt.Printf("%s\n", id)
	}
}