Beispiel #1
0
func (s Story) save(sr *server) error {
	id := s.key()
	txn := graph.NewTransaction()
	txn.AddQuad(quad.Quad{Subject: id, Predicate: TypeType, Object: TypeStory})
	txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryID, Object: itoa(s.Id)})
	txn.AddQuad(quad.Quad{Subject: id, Predicate: SiteID, Object: Site_name[int32(s.Site)]})
	if s.Exists {
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryTitle, Object: s.Title})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryCategory, Object: s.Category})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryImage, Object: s.Image})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryDescription, Object: s.Desc})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryURL, Object: s.Url})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryDL, Object: s.Dl})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryWordCount, Object: itoa(s.WordCount)})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryDateSubmit, Object: itoa(s.DateSubmit)})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryDateUpdate, Object: itoa(s.DateUpdate)})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryReviewCount, Object: itoa(s.Reviews)})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryChapters, Object: itoa(s.Chapters)})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryFavorites, Object: itoa(s.Favorites)})
		txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryComplete, Object: strconv.FormatBool(s.Complete)})
		for _, by := range s.FavedBy {
			txn.AddQuad(quad.Quad{Subject: id, Predicate: StoryFavoritedBy, Object: by})
			txn.AddQuad(quad.Quad{Subject: by, Predicate: UserFavoriteStory, Object: id})
		}
	}
	return sr.graph.ApplyTransaction(txn)
}
Beispiel #2
0
func (u User) save(s *server) error {
	id := u.key()
	txn := graph.NewTransaction()
	txn.AddQuad(quad.Quad{Subject: id, Predicate: TypeType, Object: TypeUser})
	txn.AddQuad(quad.Quad{Subject: id, Predicate: UserID, Object: u.Id})
	txn.AddQuad(quad.Quad{Subject: id, Predicate: SiteID, Object: Site_name[int32(u.Site)]})
	if u.Exists {
		txn.AddQuad(quad.Quad{Subject: id, Predicate: UserName, Object: u.Name})
		for _, story := range u.Stories {
			txn.AddQuad(quad.Quad{Subject: id, Predicate: UserStory, Object: story})
			txn.AddQuad(quad.Quad{Subject: story, Predicate: StoryAuthor, Object: id})
		}
		for _, story := range u.FavStories {
			txn.AddQuad(quad.Quad{Subject: id, Predicate: UserFavoriteStory, Object: story})
			txn.AddQuad(quad.Quad{Subject: story, Predicate: StoryFavoritedBy, Object: id})
		}
		for _, author := range u.FavAuthors {
			txn.AddQuad(quad.Quad{Subject: id, Predicate: UserFavoriteAuthor, Object: author})
			txn.AddQuad(quad.Quad{Subject: author, Predicate: UserFavoritedBy, Object: id})
		}
	}
	return s.graph.ApplyTransaction(txn)
}
Beispiel #3
0
func TestTransaction(t *testing.T) {
	qs, w, _ := makeTestStore(simpleGraph)
	size := qs.Size()

	tx := graph.NewTransaction()
	tx.AddQuad(quad.Quad{
		Subject:   "E",
		Predicate: "follows",
		Object:    "G",
		Label:     ""})
	tx.RemoveQuad(quad.Quad{
		Subject:   "Non",
		Predicate: "existent",
		Object:    "quad",
		Label:     ""})

	err := w.ApplyTransaction(tx)
	if err == nil {
		t.Error("Able to remove a non-existent quad")
	}
	if size != qs.Size() {
		t.Error("Appended a new quad in a failed transaction")
	}
}
Beispiel #4
0
func TestTransaction(t *testing.T) {
	qs, w, _ := makeTestStore(simpleGraph)
	size := qs.Size()

	tx := graph.NewTransaction()
	tx.AddQuad(quad.MakeRaw(
		"E",
		"follows",
		"G",
		""))
	tx.RemoveQuad(quad.MakeRaw(
		"Non",
		"existent",
		"quad",
		""))

	err := w.ApplyTransaction(tx)
	if err == nil {
		t.Error("Able to remove a non-existent quad")
	}
	if size != qs.Size() {
		t.Error("Appended a new quad in a failed transaction")
	}
}