當前位置: 首頁>>代碼示例>>Golang>>正文


Golang hstore.Hstore類代碼示例

本文整理匯總了Golang中github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/pq/hstore.Hstore的典型用法代碼示例。如果您正苦於以下問題:Golang Hstore類的具體用法?Golang Hstore怎麽用?Golang Hstore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Hstore類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Add

func (r *AppRepo) Add(data interface{}) error {
	app := data.(*ct.App)
	if app.Name == "" {
		return ct.ValidationError{"name", "must not be blank"}
	}
	if len(app.Name) > 30 || !appNamePattern.MatchString(app.Name) {
		return ct.ValidationError{"name", "is invalid"}
	}
	if app.ID == "" {
		app.ID = utils.UUID()
	}
	var meta hstore.Hstore
	if len(app.Meta) > 0 {
		meta.Map = make(map[string]sql.NullString, len(app.Meta))
		for k, v := range app.Meta {
			meta.Map[k] = sql.NullString{String: v, Valid: true}
		}
	}
	err := r.db.QueryRow("INSERT INTO apps (app_id, name, protected, meta) VALUES ($1, $2, $3, $4) RETURNING created_at, updated_at", app.ID, app.Name, app.Protected, meta).Scan(&app.CreatedAt, &app.UpdatedAt)
	app.ID = cleanUUID(app.ID)
	if !app.Protected && r.defaultDomain != "" {
		route := (&strowger.HTTPRoute{
			Domain:  fmt.Sprintf("%s.%s", app.Name, r.defaultDomain),
			Service: app.Name + "-web",
		}).ToRoute()
		route.ParentRef = routeParentRef(app)
		if err := r.router.CreateRoute(route); err != nil {
			log.Printf("Error creating default route for %s: %s", app.Name, err)
		}
	}
	return err
}
開發者ID:upton,項目名稱:flynn,代碼行數:32,代碼來源:app.go

示例2: Update

func (r *AppRepo) Update(id string, data map[string]interface{}) (interface{}, error) {
	tx, err := r.db.Begin()
	if err != nil {
		return nil, err
	}
	app, err := selectApp(tx, id, true)
	if err != nil {
		tx.Rollback()
		return nil, err
	}

	for k, v := range data {
		switch k {
		case "strategy":
			strategy, ok := v.(string)
			if !ok {
				tx.Rollback()
				return nil, fmt.Errorf("controller: expected string, got %T", v)
			}
			app.Strategy = strategy
			if _, err := tx.Exec("UPDATE apps SET strategy = $2, updated_at = now() WHERE app_id = $1", app.ID, app.Strategy); err != nil {
				tx.Rollback()
				return nil, err
			}
		case "meta":
			data, ok := v.(map[string]interface{})
			if !ok {
				tx.Rollback()
				return nil, fmt.Errorf("controller: expected map[string]interface{}, got %T", v)
			}
			var meta hstore.Hstore
			meta.Map = make(map[string]sql.NullString, len(data))
			app.Meta = make(map[string]string, len(data))
			for k, v := range data {
				s, ok := v.(string)
				if !ok {
					tx.Rollback()
					return nil, fmt.Errorf("controller: expected string, got %T", v)
				}
				meta.Map[k] = sql.NullString{String: s, Valid: true}
				app.Meta[k] = s
			}
			if _, err := tx.Exec("UPDATE apps SET meta = $2, updated_at = now() WHERE app_id = $1", app.ID, meta); err != nil {
				tx.Rollback()
				return nil, err
			}
		}
	}

	if err := createEvent(tx.Exec, &ct.Event{
		AppID:      app.ID,
		ObjectID:   app.ID,
		ObjectType: ct.EventTypeApp,
	}, app); err != nil {
		tx.Rollback()
		return nil, err
	}

	return app, tx.Commit()
}
開發者ID:suifing,項目名稱:flynn,代碼行數:60,代碼來源:app.go

示例3: metaToHstore

func metaToHstore(m map[string]string) hstore.Hstore {
	var s hstore.Hstore
	if len(m) > 0 {
		s.Map = make(map[string]sql.NullString, len(m))
		for k, v := range m {
			s.Map[k] = sql.NullString{String: v, Valid: true}
		}
	}
	return s
}
開發者ID:technosophos,項目名稱:flynn,代碼行數:10,代碼來源:common.go

示例4: Update

func (r *AppRepo) Update(id string, data map[string]interface{}) (interface{}, error) {
	tx, err := r.db.Begin()
	if err != nil {
		return nil, err
	}
	app, err := selectApp(tx, id, true)
	if err != nil {
		tx.Rollback()
		return nil, err
	}

	for k, v := range data {
		switch k {
		case "protected":
			protected, ok := v.(bool)
			if !ok {
				tx.Rollback()
				return nil, fmt.Errorf("controller: expected bool, got %T", v)
			}
			if app.Protected != protected {
				if _, err := tx.Exec("UPDATE apps SET protected = $2, updated_at = now() WHERE app_id = $1", app.ID, protected); err != nil {
					tx.Rollback()
					return nil, err
				}
				app.Protected = protected
			}
		case "meta":
			data, ok := v.(map[string]interface{})
			if !ok {
				tx.Rollback()
				return nil, fmt.Errorf("controller: expected map[string]interface{}, got %T", v)
			}
			var meta hstore.Hstore
			meta.Map = make(map[string]sql.NullString, len(data))
			app.Meta = make(map[string]string, len(data))
			for k, v := range data {
				s, ok := v.(string)
				if !ok {
					tx.Rollback()
					return nil, fmt.Errorf("controller: expected string, got %T", v)
				}
				meta.Map[k] = sql.NullString{String: s, Valid: true}
				app.Meta[k] = s
			}
			if _, err := tx.Exec("UPDATE apps SET meta = $2, updated_at = now() WHERE app_id = $1", app.ID, meta); err != nil {
				tx.Rollback()
				return nil, err
			}
		}
	}

	return app, tx.Commit()
}
開發者ID:upton,項目名稱:flynn,代碼行數:53,代碼來源:app.go


注:本文中的github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/pq/hstore.Hstore類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。