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


Golang gorp.Transaction类代码示例

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


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

示例1: saveReactionAndUpdatePost

func saveReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.Reaction) error {
	if err := transaction.Insert(reaction); err != nil {
		return err
	}

	return updatePostForReactions(transaction, reaction.PostId)
}
开发者ID:Rudloff,项目名称:platform,代码行数:7,代码来源:sql_reaction_store.go

示例2: CountRows

func CountRows(tableName, columnName string, txn *gorp.Transaction) (int64, error) {
	count, err := txn.SelectInt(fmt.Sprintf(SQL_MODEL_COUNT, columnName, tableName))
	if err != nil {
		return -1, err
	}

	return count, nil
}
开发者ID:patrickpreuss,项目名称:flogviewer,代码行数:8,代码来源:common.go

示例3: deleteOAuthTokens

func (as SqlOAuthStore) deleteOAuthTokens(transaction *gorp.Transaction, clientId string) StoreResult {
	result := StoreResult{}

	if _, err := transaction.Exec("DELETE FROM OAuthAccessData WHERE ClientId = :Id", map[string]interface{}{"Id": clientId}); err != nil {
		result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error())
		return result
	}

	return as.deleteAppExtras(transaction, clientId)
}
开发者ID:cloudron-io,项目名称:mattermost,代码行数:10,代码来源:sql_oauth_store.go

示例4: update

func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
	result := StoreResult{}

	if _, err := transaction.Update(preference); err != nil {
		result.Err = model.NewAppError("SqlPreferenceStore.update", "We couldn't update the preference",
			"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error())
	}

	return result
}
开发者ID:mf1389004071,项目名称:platform,代码行数:10,代码来源:sql_preference_store.go

示例5: save

func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
	result := StoreResult{}

	preference.PreUpdate()

	if result.Err = preference.IsValid(); result.Err != nil {
		return result
	}

	params := map[string]interface{}{
		"UserId":   preference.UserId,
		"Category": preference.Category,
		"Name":     preference.Name,
		"Value":    preference.Value,
	}

	if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
		if _, err := transaction.Exec(
			`INSERT INTO
				Preferences
				(UserId, Category, Name, Value)
			VALUES
				(:UserId, :Category, :Name, :Value)
			ON DUPLICATE KEY UPDATE
				Value = :Value`, params); err != nil {
			result.Err = model.NewLocAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error())
		}
	} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
		// postgres has no way to upsert values until version 9.5 and trying inserting and then updating causes transactions to abort
		count, err := transaction.SelectInt(
			`SELECT
				count(0)
			FROM
				Preferences
			WHERE
				UserId = :UserId
				AND Category = :Category
				AND Name = :Name`, params)
		if err != nil {
			result.Err = model.NewLocAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error())
			return result
		}

		if count == 1 {
			s.update(transaction, preference)
		} else {
			s.insert(transaction, preference)
		}
	} else {
		result.Err = model.NewLocAppError("SqlPreferenceStore.save", "store.sql_preference.save.missing_driver.app_error", nil,
			"Failed to update preference because of missing driver")
	}

	return result
}
开发者ID:cloudron-io,项目名称:mattermost,代码行数:55,代码来源:sql_preference_store.go

示例6: InitUtmstatusTable

func InitUtmstatusTable(txn *gorp.Transaction) {
	rows := []*UtmStatus{
		&UtmStatus{0, "passthrough"},
		&UtmStatus{0, "blocked"},
	}

	for _, r := range rows {
		if err := txn.Insert(r); err != nil {
			panic(err)
		}
	}
}
开发者ID:patrickpreuss,项目名称:flogviewer,代码行数:12,代码来源:utmstatus.go

示例7: deleteReactionAndUpdatePost

func deleteReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.Reaction) error {
	if _, err := transaction.Exec(
		`DELETE FROM
			Reactions
		WHERE
			PostId = :PostId AND
			UserId = :UserId AND
			EmojiName = :EmojiName`,
		map[string]interface{}{"PostId": reaction.PostId, "UserId": reaction.UserId, "EmojiName": reaction.EmojiName}); err != nil {
		return err
	}

	return updatePostForReactions(transaction, reaction.PostId)
}
开发者ID:Rudloff,项目名称:platform,代码行数:14,代码来源:sql_reaction_store.go

示例8: insert

func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
	result := StoreResult{}

	if err := transaction.Insert(preference); err != nil {
		if IsUniqueConstraintError(err.Error(), []string{"UserId", "preferences_pkey"}) {
			result.Err = model.NewLocAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.exists.app_error", nil,
				"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error())
		} else {
			result.Err = model.NewLocAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.save.app_error", nil,
				"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error())
		}
	}

	return result
}
开发者ID:cloudron-io,项目名称:mattermost,代码行数:15,代码来源:sql_preference_store.go

示例9: GetUserByName

func GetUserByName(txn *gorp.Transaction, name string) (*models.User, error) {
	qrows := make([]models.User, 0)

	_, err := txn.Select(&qrows, SQL_USER_BYNAME, map[string]interface{}{
		"name": name,
	})
	if err != nil {
		return nil, err
	}
	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
开发者ID:patrickpreuss,项目名称:flogviewer,代码行数:15,代码来源:user.go

示例10: deleteAppExtras

func (as SqlOAuthStore) deleteAppExtras(transaction *gorp.Transaction, clientId string) StoreResult {
	result := StoreResult{}

	if _, err := transaction.Exec(
		`DELETE FROM
			Preferences
		WHERE
			Category = :Category
			AND Name = :Name`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, "Name": clientId}); err != nil {
		result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_preference.delete.app_error", nil, err.Error())
		return result
	}

	return result
}
开发者ID:cloudron-io,项目名称:mattermost,代码行数:15,代码来源:sql_oauth_store.go

示例11: insert

func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *model.Preference) StoreResult {
	result := StoreResult{}

	if err := transaction.Insert(preference); err != nil {
		if IsUniqueConstraintError(err.Error(), "UserId", "preferences_pkey") {
			result.Err = model.NewAppError("SqlPreferenceStore.insert", "A preference with that user id, category, and name already exists",
				"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error())
		} else {
			result.Err = model.NewAppError("SqlPreferenceStore.insert", "We couldn't save the preference",
				"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error())
		}
	}

	return result
}
开发者ID:mf1389004071,项目名称:platform,代码行数:15,代码来源:sql_preference_store.go

示例12: GetDeviceBySerial

func GetDeviceBySerial(txn *gorp.Transaction, serial string) (*models.Device, error) {
	qrows := make([]models.Device, 0)

	_, err := txn.Select(&qrows, SQL_DEVICE_BYSERIAL, map[string]interface{}{
		"serial": serial,
	})
	if err != nil {
		return nil, err
	}

	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
开发者ID:patrickpreuss,项目名称:flogviewer,代码行数:16,代码来源:device.go

示例13: GetCategoryByDescription

func GetCategoryByDescription(
	txn *gorp.Transaction,
	desc string) (*models.Category, error) {

	qrows := make([]models.Category, 0)

	_, err := txn.Select(&qrows, SQL_CATEGORY_BYNAME, map[string]interface{}{
		"desc": desc,
	})
	if err != nil {
		return nil, err
	}
	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
开发者ID:patrickpreuss,项目名称:flogviewer,代码行数:18,代码来源:category.go

示例14: InitLoglevelTable

func InitLoglevelTable(txn *gorp.Transaction) {
	rows := []*LogLevel{
		&LogLevel{0, "emergency"},
		&LogLevel{0, "alert"},
		&LogLevel{0, "critical"},
		&LogLevel{0, "error"},
		&LogLevel{0, "warning"},
		&LogLevel{0, "notice"},
		&LogLevel{0, "information"},
		&LogLevel{0, "debug"},
	}

	for _, r := range rows {
		if err := txn.Insert(r); err != nil {
			panic(err)
		}
	}
}
开发者ID:patrickpreuss,项目名称:flogviewer,代码行数:18,代码来源:loglevel.go

示例15: GetLoglevelByName

func GetLoglevelByName(
	txn *gorp.Transaction,
	name string) (*models.LogLevel, error) {
	qrows := make([]models.LogLevel, 0)

	_, err := txn.Select(&qrows, SQL_LOGLEVEL_BYDESC, map[string]interface{}{
		"name": name,
	})
	if err != nil {
		return nil, err
	}

	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
开发者ID:patrickpreuss,项目名称:flogviewer,代码行数:18,代码来源:loglevel.go


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