func (f *FilesTable) GetInEmail(owner string, email string, name string) ([]*models.File, error) { e, err := f.Emails.GetEmail(email) if err != nil { return nil, err } query, err := f.GetTable().Filter(func(row gorethink.Term) gorethink.Term { return gorethink.And( row.Field("owner").Eq(gorethink.Expr(owner)), gorethink.Expr(e.Files).Contains(row.Field("id")), row.Field("name").Eq(gorethink.Expr(name)), ) }).Run(f.GetSession()) if err != nil { return nil, err } var result []*models.File err = query.All(&result) if err != nil { return nil, err } return result, nil }
func (rd *rethinkDriver) PutBuild(build *datastore.Build) (string, error) { result, err := r.Table("builds").Insert( r.Table("builds").Filter( r.And( r.Row.Field("job_id").Eq(build.JobId), r.Row.Field("number").Eq(build.Number), ), ).CoerceTo("array").Do(func(docs r.Term) interface{} { return r.Branch( r.Or(docs.IsEmpty(), docs.Field("id").Contains(build.Id)), build, r.Error("Build with job_id and number exists"), ) }), r.InsertOpts{Conflict: "replace"}, ).RunWrite(rd.session) if err != nil { return "", err } if len(result.GeneratedKeys) > 0 { return result.GeneratedKeys[0], nil } else { return build.Id, nil } }
func (rd *rethinkDriver) GetBuild(jobKey string, buildNumber int64) (*datastore.Build, error) { cursor, err := r.Table("builds").Filter( r.And( r.Row.Field("job_id").Eq(jobKey), r.Row.Field("number").Eq(buildNumber), ), ).Run(rd.session) if err != nil { return nil, err } var build datastore.Build err = cursor.One(&build) if err != nil { return nil, err } return &build, nil }
func (t *ThreadsTable) CountByLabelUnread(label string) (int, error) { var result int cursor, err := t.GetTable().Filter(func(row gorethink.Term) gorethink.Term { return gorethink.And( row.Field("labels").Contains(label), row.Field("is_read").Eq(false), ) }).Count().Run(t.GetSession()) if err != nil { return 0, err } err = cursor.One(&result) if err != nil { return 0, err } return result, nil }