• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang gorethink.Table函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: deleteHandler

func deleteHandler(w http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	id := vars["id"]
	if id == "" {
		http.NotFound(w, req)
		return
	}

	// Check that the item exists
	res, err := r.Table("items").Get(id).Run(session)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if res.IsNil() {
		http.NotFound(w, req)
		return
	}

	// Delete the item
	_, err = r.Table("items").Get(id).Delete().RunWrite(session)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	http.Redirect(w, req, "/", http.StatusFound)
}
开发者ID:ramigg,项目名称:GoRethink_TodoDemo,代码行数:29,代码来源:server.go


示例2: UserUtils

func UserUtils(res http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {
		name := req.FormValue("name")
		user := &User{name}
		_, err := r.Table("users").Insert(user).RunWrite(session)
		if err != nil {
			fmt.Print("Error: %s", err)
		} else {
			io.WriteString(res, "Insertado con exito")
		}
	}
	if req.Method == "DELETE" {
		id := req.FormValue("id")
		_, err := r.Table("users").Get(id).Delete().RunWrite(session)
		if err != nil {
			fmt.Print("Error: %s", err)
		} else {
			io.WriteString(res, "Eliminado con exito")
		}
	}
	if req.Method == "PUT" {
		id := req.FormValue("id")
		name := req.FormValue("name")
		user := &User{name}
		_, err := r.Table("users").Get(id).Update(user).RunWrite(session)
		if err != nil {
			fmt.Print("Error: %s", err)
		} else {
			io.WriteString(res, "Actualizado con exito")
		}
	}
}
开发者ID:dev-lusaja,项目名称:RealTime-GORethink,代码行数:32,代码来源:Server.go


示例3: toggleHandler

func toggleHandler(w http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	id := vars["id"]
	if id == "" {
		http.NotFound(w, req)
		return
	}

	// Check that the item exists
	res, err := r.Table("items").Get(id).Run(session)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if res.IsNil() {
		http.NotFound(w, req)
		return
	}

	// Toggle the item
	_, err = r.Table("items").Get(id).Update(map[string]interface{}{"Status": r.Branch(
		r.Row.Field("Status").Eq("active"),
		"complete",
		"active",
	)}).RunWrite(session)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	http.Redirect(w, req, "/", http.StatusFound)
}
开发者ID:ramigg,项目名称:GoRethink_TodoDemo,代码行数:33,代码来源:server.go


示例4: ToggleNode

func (s *HTTPServer) ToggleNode(w http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	id := vars["id"]
	if id == "" {
		http.NotFound(w, req)
		return
	}

	// Check that the item exists
	res, err := r.Table(tableIpxe).Get(id).RunRow(session)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if res.IsNil() {
		http.NotFound(w, req)
		return
	}

	_, err = r.Table(tableIpxe).Get(id).Update(map[string]interface{}{"Status": r.Branch(
		r.Row.Field("Status").Eq("AVAILABLE"),
		"UNAVAILABLE",
		"AVAILABLE",
	)}).RunWrite(session)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	http.Redirect(w, req, "/", http.StatusFound)
}
开发者ID:EntropyWorks,项目名称:enforcer,代码行数:31,代码来源:node_endpoint.go


示例5: RemoveEngine

func (m *Manager) RemoveEngine(id string) error {
	var engine *shipyard.Engine
	res, err := r.Table(tblNameConfig).Filter(map[string]string{"id": id}).Run(m.session)
	if err != nil {
		return err
	}
	if err := res.One(&engine); err != nil {
		if err == r.ErrEmptyResult {
			return nil
		}
		return err
	}
	evt := &shipyard.Event{
		Type:    "remove-engine",
		Message: fmt.Sprintf("addr=%s", engine.Engine.Addr),
		Time:    time.Now(),
		Engine:  engine.Engine,
		Tags:    []string{"cluster"},
	}
	if err := m.SaveEvent(evt); err != nil {
		return err
	}
	if _, err := r.Table(tblNameConfig).Get(id).Delete().RunWrite(m.session); err != nil {
		return err
	}
	m.init()
	return nil
}
开发者ID:rbramwell,项目名称:shipyard,代码行数:28,代码来源:manager.go


示例6: createHub

func createHub(user sessionauth.User, newHub hub, rend render.Render, req *http.Request) {

	var hubInDB hub
	query := r.Table("hub").Filter(r.Row.Field("name").Eq(newHub.HubName))
	row, err := query.RunRow(dbSession)

	if err == nil && !row.IsNil() {
		// Register, error case.
		if err := row.Scan(&hubInDB); err != nil {
			fmt.Println("Error reading DB")
		} else {
			fmt.Println("User already exists. Redirecting to login.")
		}

		rend.Redirect(sessionauth.RedirectUrl)
		return
	} else { // User doesn't exist, continue with registration.
		if row.IsNil() {
			fmt.Println("User doesn't exist. Registering...")
		} else {
			fmt.Println(err)
		}
	}

	r.Table("hub").Insert(newHub).RunWrite(dbSession)
	fmt.Println("New hub done. Try to con")

	rend.Redirect(sessionauth.RedirectUrl)
}
开发者ID:jmptrader,项目名称:chatgo,代码行数:29,代码来源:hub.go


示例7: init

func init() {
	h = &hubManager{
		HubMap:  make(map[string]*hub),
		EdgeMap: &Edges{},

		newHub:     make(chan hubConnMsg, 256),
		addEdge:    make(chan hubConnMsg, 2048),
		remEdge:    make(chan hubConnMsg, 2048),
		bCastToHub: make(chan hubConnMsg, 2048),
	}

	var err error
	h.DefaultHub, err = newHub("default", nil)

	if err != nil {
		fmt.Println("Default insert error, still running hub.", err)
	}

	// create index
	_, err = r.Table("hub").IndexCreate("name").Run(dbSession)
	fmt.Println("create index name error: ", err)
	_, err = r.Table("user").IndexCreate("email").Run(dbSession)
	fmt.Println("create index user email error: ", err)

	go h.run()
}
开发者ID:jmptrader,项目名称:chatgo,代码行数:26,代码来源:hub.go


示例8: init

func init() {
	flag.Parse()
	err := gcfg.ReadFileInto(&cfg, *configFile)
	if err != nil {
		log.Fatal(err)
	}

	session, err = r.Connect(r.ConnectOpts{
		Address:  cfg.Database.Host + ":" + cfg.Database.Port, //localhost:28015
		Database: cfg.Database.DB,                             //DB: cats
	})
	if err != nil {
		log.Fatal("Could not connect")
	}
	res, err := r.DBCreate(cfg.Database.DB).RunWrite(session)
	if err != nil {
		log.Println(err.Error())
	}

	fmt.Printf("%d DB created\n", res.DBsCreated)
	r.DB(cfg.Database.DB).TableCreate("instacat").Run(session)
	log.Println("Create table instacat.")
	r.Table("instacat").IndexCreate("time").Run(session)
	log.Println("Create index time.")
	r.Table("instacat").IndexCreate("place", r.IndexCreateOpts{Geo: true}).Run(session)
	log.Println("Create index place.")
}
开发者ID:jimmyplaza,项目名称:RethinkDB-Instagram,代码行数:27,代码来源:main.go


示例9: SaveAccount

func (m *Manager) SaveAccount(account *shipyard.Account) error {
	pass := account.Password
	hash, err := m.authenticator.Hash(pass)
	if err != nil {
		return err
	}
	// check if exists; if so, update
	acct, err := m.Account(account.Username)
	if err != nil && err != ErrAccountDoesNotExist {
		return err
	}
	account.Password = hash
	if acct != nil {
		if _, err := r.Table(tblNameAccounts).Filter(map[string]string{"username": account.Username}).Update(map[string]string{"password": hash}).RunWrite(m.session); err != nil {
			return err
		}
		return nil
	}
	if _, err := r.Table(tblNameAccounts).Insert(account).RunWrite(m.session); err != nil {
		return err
	}
	evt := &shipyard.Event{
		Type:    "add-account",
		Time:    time.Now(),
		Message: fmt.Sprintf("username=%s", account.Username),
		Tags:    []string{"cluster", "security"},
	}
	if err := m.SaveEvent(evt); err != nil {
		return err
	}
	return nil
}
开发者ID:rbramwell,项目名称:shipyard,代码行数:32,代码来源:manager.go


示例10: getRemoteObject

func getRemoteObject(url string) (Object, error) {
	rows, err := gorethink.Table("objects").GetAllByIndex("url", url).Run(session)

	var row Object
	err = rows.One(&row)
	if err != nil && err != gorethink.ErrEmptyResult {
		return Object{}, err
	}

	if err == gorethink.ErrEmptyResult {
		res, err := http.Get(url)
		if err != nil {
			return Object{}, err
		}
		defer res.Body.Close()

		content, err := ioutil.ReadAll(res.Body)
		if err != nil {
			return Object{}, err
		}

		result, err := gorethink.Table("objects").Insert(Object{URL: url, Content: content}).RunWrite(session)
		if err != nil {
			return Object{}, err
		}
		return Object{ID: result.GeneratedKeys[0], URL: url, Content: content}, nil
	}
	return row, nil
}
开发者ID:nogara,项目名称:titanbot,代码行数:29,代码来源:db.go


示例11: pushIndex

func pushIndex(session *gorethink.Session) {
	i := 0
	fmt.Println("Pushing title")
	for i < len(titles) {
		var chunk []*Title
		if i+100 < len(titles) {
			chunk = titles[i : i+100]
		} else {
			chunk = titles[i:len(titles)]
		}
		gorethink.Table("titles").Insert(chunk, gorethink.InsertOpts{Durability: "soft", Upsert: true}).RunWrite(session)
		fmt.Println("Title %d / %d\n", i, len(titles))
		i += 100
	}
	fmt.Println("Pushing index")
	idxChunk := []*Index{}
	i = 0
	for _, idx := range idxes {
		i++
		if len(idxChunk) < 100 {
			idxChunk = append(idxChunk, idx)
			continue
		}
		gorethink.Table("indexes").Insert(idxChunk, gorethink.InsertOpts{Durability: "soft", Upsert: true}).RunWrite(session)
		fmt.Println("Index %d / %d\n", i, len(idxes))
		idxChunk = []*Index{}
	}
}
开发者ID:keimoon,项目名称:voicewiki,代码行数:28,代码来源:index.go


示例12: PutBuild

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
	}
}
开发者ID:miquella,项目名称:mason-ci,代码行数:26,代码来源:driver.go


示例13: UpdateTripPlaces

//UpdateTripPlaces update trip places
func (t *Trips) UpdateTripPlaces(w rest.ResponseWriter, r *rest.Request) {
	id := r.PathParam("id")
	res, err := rethink.Table(tableName).Get(id).Run(t.Conn)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if res.IsNil() {
		rest.NotFound(w, r)
		return
	}
	var trip *Trip
	res.One(&trip)

	tripPlaces := []TripPlace{}
	err = r.DecodeJsonPayload(&tripPlaces)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	trip.Updated = time.Now()
	trip.Places = tripPlaces
	trip.TotalPlaces = len(tripPlaces)

	_, err = rethink.Table(tableName).Get(id).Update(trip).RunWrite(t.Conn)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteJson(&trip)
}
开发者ID:yetis-br,项目名称:travelPlanning,代码行数:32,代码来源:trip.go


示例14: buy

func buy(w http.ResponseWriter, q *http.Request) {

	ctx, err := NewContext(q)
	if err != nil {
		log.Println(err)
	}

	if q.Method == "POST" {
		//find last code(chek if it) of order +1 add to db
		t := time.Now()

		order := ctx.Session.Values["Order"].(*Order)

		a := false
		for a == false {

			orderId := getorderId(t.Format("2006-01-02"), order.Customer.Email, randStr(4, "alphanum"))

			res, err := r.Table("orders").Filter(map[string]interface{}{"OrderNumber": orderId}).Run(ctx.Db)

			if err != nil {
				log.Println(err)
			}

			if res.IsNil() == true {
				p := findproductCart{
					CartArray: order.CartOrderd,
				}
				_, total := p.total()

				P, _, _, _ := statuses()
				//P, PfS, S, D := statuses()

				order.OrderNumber = orderId
				order.Status = P
				order.Date = t.Format("2006-01-02 15:04")
				order.Total = FloatToString(total)

				_, err = r.Table("orders").Insert(order).RunWrite(ctx.Db)
				if err != nil {
					log.Println(err)
				}
				ctx.Session.Values["Order"] = nil
				ctx.Session.Save(q, w)
				a = true
			} else {
				a = false
			}

		}

	} else {

		order := ctx.Session.Values["Order"].(*Order)
		newmap := map[string]interface{}{"Shippingadress": order.ShippingAdress, "Billingadress": order.BillingAdress, "Paymethod": order.PaymentMethod, "shippingOpt": order.Shipping.ShippingMethod, "Product": order.CartOrderd}
		render(w, "buy", newmap)
	}
}
开发者ID:ivansyi,项目名称:goShop,代码行数:58,代码来源:app.go


示例15: SaveAuthorization

func (s *Rethinkdb) SaveAuthorization(auth *dialogue.Authorization) error {
	// delete exiting
	rdb.Table(AUTH_TABLE).Filter(map[string]string{"username": auth.Username}).Delete().Run(s.session)
	// add auth
	if _, err := rdb.Table(AUTH_TABLE).Insert(auth).Run(s.session); err != nil {
		return err
	}
	return nil
}
开发者ID:carriercomm,项目名称:dialogue-1,代码行数:9,代码来源:db.go


示例16: CheckByName

func (d *Deployment) CheckByName(name string) (check Check, err error) {
	cur, err := r.Branch(
		r.Table("deployments").Get(d.Id).Field("checks").Filter(map[string]interface{}{"name": name}).IsEmpty(),
		r.Table("checks").GetAllByIndex("type_name", []string{d.Type, name}),
		r.Table("deployments").Get(d.Id).Field("checks").Filter(map[string]interface{}{"name": name}),
	).Run(session)
	defer cur.Close()
	err = cur.One(&check)
	if err != nil {
		return check, err
	}
	return check, nil
}
开发者ID:adamliesko,项目名称:platform-ws-services,代码行数:13,代码来源:model_deployment.go


示例17: MergedAlertSettings

func (d *Deployment) MergedAlertSettings() (settings Settings, err error) {
	cur, err := r.Branch(
		r.Table("groups").Get(d.GroupId),
		r.Table("groups").EqJoin("id", r.Table("deployments"), r.EqJoinOpts{Index: "group_id"}).Zip().Filter(map[string]interface{}{"id": d.Id}).Field("settings"),
		r.Table("deployments").Get(d.Id).Field("settings"),
	).Run(session)
	defer cur.Close()
	err = cur.One(&settings)
	if err != nil {
		return settings, err
	}
	return settings, nil
}
开发者ID:adamliesko,项目名称:platform-ws-services,代码行数:13,代码来源:model_deployment.go


示例18: createIndexes

func createIndexes() error {
	// Create a secondary index on the username field.
	_, err := r.Table(DBTableUsers).IndexCreate(DBTableUsersUsernameIndex).Run(db.Session)
	if err != nil {
		return err
	}

	// Wait for the index to be ready to use.
	_, err = r.Table(DBTableUsers).IndexWait(DBTableUsersUsernameIndex).Run(db.Session)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:15,代码来源:db.go


示例19: SaveAccount

func (m DefaultManager) SaveAccount(account *auth.Account) error {
	var (
		hash      string
		eventType string
	)
	if account.Password != "" {
		h, err := auth.Hash(account.Password)
		if err != nil {
			return err
		}

		hash = h
	}
	// check if exists; if so, update
	acct, err := m.Account(account.Username)
	if err != nil && err != ErrAccountDoesNotExist {
		return err
	}

	// update
	if acct != nil {
		updates := map[string]interface{}{
			"first_name": account.FirstName,
			"last_name":  account.LastName,
			"roles":      account.Roles,
		}
		if account.Password != "" {
			updates["password"] = hash
		}

		if _, err := r.Table(tblNameAccounts).Filter(map[string]string{"username": account.Username}).Update(updates).RunWrite(m.session); err != nil {
			return err
		}

		eventType = "update-account"
	} else {
		account.Password = hash
		if _, err := r.Table(tblNameAccounts).Insert(account).RunWrite(m.session); err != nil {
			return err
		}

		eventType = "add-account"
	}

	m.logEvent(eventType, fmt.Sprintf("username=%s", account.Username), []string{"security"})

	return nil
}
开发者ID:nfoonf,项目名称:shipyard,代码行数:48,代码来源:manager.go


示例20: SaveEvent

func (m DefaultManager) SaveEvent(event *shipyard.Event) error {
	if _, err := r.Table(tblNameEvents).Insert(event).RunWrite(m.session); err != nil {
		return err
	}

	return nil
}
开发者ID:nfoonf,项目名称:shipyard,代码行数:7,代码来源:manager.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gorethink.Cursor类代码示例发布时间:2022-05-23
下一篇:
Golang gorethink.JSON函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap