示例#1
0
func (this *Product) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	} else {
		this.UpdatedAt = time.Now()
	}
	return mgodb.Save(PRODUCTS, this)
}
示例#2
0
func (this *Note) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	} else {
		this.UpdatedAt = time.Now()
	}
	return mgodb.Save(NOTES, this)
}
示例#3
0
func (this *Brand) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	} else {
		this.UpdatedAt = time.Now()
	}
	return mgodb.Save(BRANDS, this)
}
示例#4
0
func (this *User) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	} else {
		this.UpdatedAt = time.Now()
	}
	this.Email = strings.ToLower(this.Email)
	return mgodb.Save(USERS, this)
}
示例#5
0
func (this *Efficacy) Save() error {
	return mgodb.Save(EFFICACIES, this)
}
示例#6
0
func TestIndexAndSearch(t *testing.T) {

	mgodb.Setup("localhost", "redisgosearch")

	client := redisgosearch.NewClient("localhost:6379", "theplant")

	e1 := &Entry{
		Id:      bson.ObjectIdHex("50344415ff3a8aa694000001"),
		GroupId: "Qortex",
		Title:   "Thread Safety",
		Content: "The connection http://google.com Send and Flush methods cannot be called concurrently with other calls to these methods. The connection Receive method cannot be called concurrently with other calls to Receive. Because the connection Do method uses Send, Flush and Receive, the Do method cannot be called concurrently with Send, Flush, Receive or Do. Unless stated otherwise, all other concurrent access is allowed.",
		Attachments: []*Attachment{
			{
				Filename:    "QORTEX UI 0.88.pdf",
				ContentType: "application/pdf",
				CreatedAt:   time.Now(),
			},
		},
		CreatedAt: time.Unix(10000, 0),
	}
	e2 := &Entry{
		Id:      bson.ObjectIdHex("50344415ff3a8aa694000002"),
		GroupId: "ASICS",
		Title:   "redis is a client for the Redis database",
		Content: "The Conn interface is the primary interface for working with Redis. Applications create connections by calling the Dial, DialWithTimeout or NewConn functions. In the future, functions will be added for creating shareded and other types of connections.",
		Attachments: []*Attachment{
			{
				Filename:    "Screen Shot 2012-08-19 at 11.52.51 AM.png",
				ContentType: "image/png",
				CreatedAt:   time.Now(),
			}, {
				Filename:    "Alternate Qortex Logo.jpg",
				ContentType: "image/jpg",
				CreatedAt:   time.Now(),
			},
		},
		CreatedAt: time.Unix(20000, 0),
	}

	mgodb.Save("entries", e1)
	client.Index(e1)

	mgodb.Save("entries", e2)
	client.Index(e2)

	var entries []*Entry
	count, err := client.Search("entries", "concurrent access", nil, 0, 10, &entries)
	if err != nil {
		t.Error(err)
	}
	if count != 1 {
		t.Error(entries)
	}
	if entries[0].Title != "Thread Safety" {
		t.Error(entries[0])
	}

	var attachments []*IndexedAttachment
	_, err = client.Search("files", "alternate qortex", map[string]string{"group": "ASICS"}, 0, 20, &attachments)
	if err != nil {
		t.Error(err)
	}

	if attachments[0].Attachment.Filename != "Alternate Qortex Logo.jpg" || len(attachments) != 1 {
		t.Error(attachments[0])
	}

	// sort
	var sorted []*Entry
	client.Search("entries", "other", nil, 0, 10, &sorted)
	if sorted[0].Id.Hex() != "50344415ff3a8aa694000002" {
		t.Error(sorted[0])
	}
}
示例#7
0
func (this *Review) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	}
	return mgodb.Save(REVIEWS, this)
}
示例#8
0
func (this *Category) Save() error {
	return mgodb.Save(CATEGORIES, this)
}
示例#9
0
func (this *FollowBrand) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	}
	return mgodb.Save(FOLLOW_BRANDS, this)
}
示例#10
0
func (this *Post) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	}
	return mgodb.Save(POSTS, this)
}
示例#11
0
func (this *OwnItem) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	}
	return mgodb.Save(OWN_ITEMS, this)
}
示例#12
0
func (this *WishItem) Save() error {
	if this.CreatedAt.IsZero() {
		this.CreatedAt = time.Now()
	}
	return mgodb.Save(WISH_ITEMS, this)
}