当前位置: 首页>>代码示例>>Golang>>正文


Golang data.DB类代码示例

本文整理汇总了Golang中github.com/elos/data.DB的典型用法代码示例。如果您正苦于以下问题:Golang DB类的具体用法?Golang DB怎么用?Golang DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: WebSensorsAgent

func WebSensorsAgent(ctx context.Context, db data.DB, u *models.User) {
	// Get the db's changes, then filter by updates, then
	// filter by whether this user can read the record
	changes := data.Filter(data.FilterKind(db.Changes(), models.EventKind), func(c *data.Change) bool {
		ok, _ := access.CanRead(db, u, c.Record)
		return ok
	})

Run:
	for {
		select {
		case c, ok := <-*changes:
			if !ok {
				break Run
			}

			switch c.Record.(*models.Event).Name {
			case WEB_SENSOR_LOCATION:
				webSensorLocation(db, u, c.Record.(*models.Event).Data)
			}
		case <-ctx.Done():
			break Run

		}
	}
}
开发者ID:elos,项目名称:gaia,代码行数:26,代码来源:web_sensors.go

示例2: execute

// execute retrieves the records matching a *query, which the user can read, and marshals them to attr maps.
//
// Errors:
//		- db.Query error
//		- access.CanRead error
//		- iter.Close error
func execute(db data.DB, u *models.User, q *query) ([]map[string]interface{}, error) {
	rs := make([]map[string]interface{}, 0)

	iter, err := db.Query(q.Kind).Limit(q.Limit).Batch(q.Batch).Skip(q.Skip).Select(q.Select).Order(q.Order...).Execute()
	if err != nil {
		return nil, err
	}

	m := models.ModelFor(q.Kind)
	for iter.Next(m) {
		ok, err := access.CanRead(db, u, m)

		if err != nil {
			return nil, err
		}

		if !ok {
			continue
		}

		temp := make(map[string]interface{})
		transfer.TransferAttrs(m, &temp)
		rs = append(rs, temp)
		m = models.ModelFor(q.Kind)
	}

	if err := iter.Close(); err != nil {
		return nil, err
	}

	return rs, nil
}
开发者ID:elos,项目名称:gaia,代码行数:38,代码来源:query.go

示例3: taskDropGoal

func taskDropGoal(db data.DB, u *models.User, eventData map[string]interface{}) {
	g, err := tag.ForName(db, u, tag.Goal)
	if err != nil {
		log.Printf("agents.taskDropGoal Error: %s", err)
		return
	}

	id, err := db.ParseID(eventData["task_id"].(string))
	if err != nil {
		log.Printf("agents.taskDropGoal Error: %s", err)
		return
	}

	t, err := models.FindTask(db, id)
	if err != nil {
		log.Printf("agents.taskMakeGoal Error: %s", err)
		return
	}

	t.ExcludeTag(g)

	if err := db.Save(t); err != nil {
		log.Printf("agents.taskMakeGoal Error: %s", err)
		return
	}
}
开发者ID:elos,项目名称:gaia,代码行数:26,代码来源:task.go

示例4: TaskAgent

func TaskAgent(ctx context.Context, db data.DB, u *models.User) {

	changes := data.Filter(data.FilterKind(db.Changes(), models.EventKind), func(c *data.Change) bool {
		ok, _ := access.CanRead(db, u, c.Record)
		return ok
	})

Run:
	for {
		select {
		case c, ok := <-*changes:
			if !ok {
				break Run
			}

			switch c.Record.(*models.Event).Name {
			case TaskMakeGoal:
				taskMakeGoal(db, u, c.Record.(*models.Event).Data)
			case TaskDropGoal:
				taskDropGoal(db, u, c.Record.(*models.Event).Data)
			}
		case <-ctx.Done():
			break Run
		}
	}

}
开发者ID:elos,项目名称:gaia,代码行数:27,代码来源:task.go

示例5: createFixture

func createFixture(ui cli.Ui, ownerID string, db data.DB) (fixture *models.Fixture, err error) {
	ui.Output("Creating a fixture")

	fixture = models.NewFixture()
	fixture.SetID(db.NewID())
	fixture.OwnerId = ownerID
	fixture.CreatedAt = time.Now()

	if fixture.Name, err = stringInput(ui, "Name of the fixture:"); err != nil {
		return
	}

	if fixture.Label, err = boolInput(ui, "Is this a label?"); err != nil {
		return
	}

	if !fixture.Label {
		if fixture.StartTime, err = timeInput(ui, "Start time of fixture?"); err != nil {
			return
		}

		if fixture.EndTime, err = timeInput(ui, "End time of fixture?"); err != nil {
			return
		}
	}

	fixture.UpdatedAt = time.Now()

	err = db.Save(fixture)
	return
}
开发者ID:elos,项目名称:elos,代码行数:31,代码来源:cal.go

示例6: newTestUserX

func newTestUserX(t *testing.T, db data.DB) *models.User {
	u := new(models.User)
	u.SetID(db.NewID())
	if err := db.Save(u); err != nil {
		t.Fatalf("Error newTestUserX: %s", err)
	}
	return u
}
开发者ID:elos,项目名称:elos,代码行数:8,代码来源:todo_test.go

示例7: newTestCalendar

func newTestCalendar(t *testing.T, db olddata.DB, u *oldmodels.User) *oldmodels.Calendar {
	c := oldmodels.NewCalendar()
	c.SetID(db.NewID())
	c.SetOwner(u)
	c.CreatedAt = time.Now()
	c.UpdatedAt = c.CreatedAt

	return c
}
开发者ID:elos,项目名称:elos,代码行数:9,代码来源:cal_test.go

示例8: newTestUser

func newTestUser(t *testing.T, db data.DB) *oldmodels.User {
	u := oldmodels.NewUser()
	u.SetID(db.NewID())
	u.CreatedAt = time.Now()
	u.UpdatedAt = time.Now()
	if err := db.Save(u); err != nil {
		t.Fatalf("Error newTestUser: %s", err)
	}
	return u
}
开发者ID:elos,项目名称:elos,代码行数:10,代码来源:todo_test.go

示例9: newTestTag

func newTestTag(t *testing.T, db data.DB, u *models.User) *models.Tag {
	tg := models.NewTag()
	tg.SetID(db.NewID())
	tg.SetOwner(u)

	if err := db.Save(tg); err != nil {
		t.Fatal(err)
	}

	return tg
}
开发者ID:elos,项目名称:elos,代码行数:11,代码来源:tag_test.go

示例10: newTestTask

func newTestTask(t *testing.T, db data.DB, u *models.User) *models.Task {
	tsk := new(models.Task)
	tsk.SetID(db.NewID())
	tsk.CreatedAt = models.TimestampFrom(time.Now())
	tsk.OwnerId = u.ID().String()
	tsk.UpdatedAt = models.TimestampFrom(time.Now())
	if err := db.Save(tsk); err != nil {
		t.Fatalf("Error newTestTask: %s", err)
	}
	return tsk
}
开发者ID:elos,项目名称:elos,代码行数:11,代码来源:todo_test.go

示例11: newTestNote

func newTestNote(t *testing.T, db data.DB, u *models.User) *models.Note {
	note := models.NewNote()
	note.SetID(db.NewID())
	note.CreatedAt = time.Now()
	note.OwnerId = u.ID().String()
	note.UpdatedAt = time.Now()
	if err := db.Save(note); err != nil {
		t.Fatal("newTestNote Error: %s", err)
	}
	return note
}
开发者ID:elos,项目名称:elos,代码行数:11,代码来源:people_test.go

示例12: newTestPerson

func newTestPerson(t *testing.T, db data.DB, u *models.User) *models.Person {
	person := models.NewPerson()
	person.SetID(db.NewID())
	person.CreatedAt = time.Now()
	person.OwnerId = u.ID().String()
	person.UpdatedAt = time.Now()
	if err := db.Save(person); err != nil {
		t.Fatalf("newTestPerson Error: %s", err)
	}
	return person
}
开发者ID:elos,项目名称:elos,代码行数:11,代码来源:people_test.go

示例13: newCalendar

func newCalendar(db data.DB, userID string) (*models.Calendar, error) {
	cal := models.NewCalendar()

	cal.SetID(db.NewID())
	cal.CreatedAt = time.Now()
	cal.Name = "Main"
	cal.OwnerId = userID
	cal.UpdatedAt = time.Now()

	return cal, db.Save(cal)
}
开发者ID:elos,项目名称:elos,代码行数:11,代码来源:cal.go

示例14: locationUpdate

func locationUpdate(db data.DB, u *models.User, e *models.Event) {
	loc, _ := e.Location(db)
	p, err := user.Profile(db, u)
	if err == data.ErrNotFound {
		p = models.NewProfile()
		p.CreatedAt = time.Now()
		p.UpdatedAt = p.CreatedAt
		p.SetID(db.NewID())
		p.SetOwner(u)
	}
	p.SetLocation(loc)
	db.Save(p)
}
开发者ID:elos,项目名称:gaia,代码行数:13,代码来源:location.go

示例15: LocationAgent

func LocationAgent(ctx context.Context, db data.DB, u *models.User) {
	locTag, err := tag.ForName(db, u, tag.Location)
	if err != nil {
		log.Fatal(err)
	}
	updTag, err := tag.ForName(db, u, tag.Update)
	if err != nil {
		log.Fatal(err)
	}

	// Get the db's changes, then filter by updates, then
	// filter by whether this user can read the record
	changes := data.Filter(data.FilterKind(db.Changes(), models.EventKind), func(c *data.Change) bool {
		ok, _ := access.CanRead(db, u, c.Record)
		if !ok {
			return false
		}

		return event.ContainsTags(c.Record.(*models.Event), locTag, updTag)
	})

Run:
	for {
		select {
		case c, ok := <-*changes:
			if !ok {
				break Run
			}

			locationUpdate(db, u, c.Record.(*models.Event))
		case <-ctx.Done():
			break Run

		}
	}
}
开发者ID:elos,项目名称:gaia,代码行数:36,代码来源:location.go


注:本文中的github.com/elos/data.DB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。