Ejemplo n.º 1
0
func lookup(domain *db.Domain) {
	if *table == "station" {
		stationdb := domain.NewStationDB()
		s, err := stationdb.Lookup(*id)
		if err != nil {
			log.Fatalf("Error looking up station: %s", err.Error())
		}
		proto.MarshalText(os.Stdout, s)
	} else if *table == "contact" {
		contactdb := domain.NewContactDB()
		s, err := contactdb.Lookup(*id)
		if err != nil {
			log.Fatalf("Error looking up contact: %s", err.Error())
		}
		proto.MarshalText(os.Stdout, s)
	} else {
		log.Fatalf("Unknown table: %s", *table)
	}
}
Ejemplo n.º 2
0
func store(domain *db.Domain) {
	if *table == "station" {
		bytes, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			log.Fatalf("Error reading proto: %s", err.Error())
		}

		var s pb.Station
		err = proto.UnmarshalText((string)(bytes), &s)
		if err != nil {
			log.Fatalf("Error parsing proto: %s", err.Error())
		}

		stationdb := domain.NewStationDB()
		err = stationdb.Store(&s)
		if err != nil {
			log.Fatalf("Error storing station: %s", err.Error())
		}

		log.Printf("Stored station.")
	} else if *table == "contact" {
		bytes, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			log.Fatalf("Error reading proto: %s", err.Error())
		}

		var s pb.Contact
		err = proto.UnmarshalText((string)(bytes), &s)
		if err != nil {
			log.Fatalf("Error parsing proto: %s", err.Error())
		}

		contactdb := domain.NewContactDB()
		err = contactdb.Store(&s)
		if err != nil {
			log.Fatalf("Error storing contact: %s", err.Error())
		}

		log.Printf("Stored contact.")
	} else {
		log.Fatalf("Unknown table: %s", *table)
	}
}
Ejemplo n.º 3
0
func restore(domain *db.Domain) {
	user_rr := getRecordReader(*backup_dir, "test-users.User.rec")
	station_rr := getRecordReader(*backup_dir, "test-stations.Station.rec")
	comment_rr := getRecordReader(*backup_dir, "test-comments.Comment.rec")
	contact_rr := getRecordReader(*backup_dir, "test-contacts.Contact.rec")

	userdb := domain.NewUserDB()
	if err := userdb.Create(); err != nil {
		log.Fatalf("Error creating user table: %s", err.Error())
	}
	stationdb := domain.NewStationDB()
	if err := stationdb.Create(); err != nil {
		log.Fatalf("Error creating station table: %s", err.Error())
	}
	commentdb := domain.NewCommentDB()
	if err := commentdb.Create(); err != nil {
		log.Fatalf("Error creating comment table: %s", err.Error())
	}
	contactdb := domain.NewContactDB()
	if err := contactdb.Create(); err != nil {
		log.Fatalf("Error creating contact table: %s", err.Error())
	}

	if err := RestoreUserTable(user_rr, userdb); err != nil {
		log.Fatalf("Error restoring user table: %s", err.Error())
	}
	if err := RestoreStationsTable(station_rr, stationdb); err != nil {
		log.Fatalf("Error restoring station table: %s", err.Error())
	}
	if err := RestoreCommentsTable(comment_rr, commentdb); err != nil {
		log.Fatalf("Error restoring comments table: %s", err.Error())
	}
	if err := RestoreContactsTable(contact_rr, contactdb); err != nil {
		log.Fatalf("Error restoring contacts table: %s", err.Error())
	}
}