Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Connection to execute multiple commands in a single conn #4982

Merged
merged 1 commit into from Jan 7, 2022
Merged

feat: add Connection to execute multiple commands in a single conn #4982

merged 1 commit into from Jan 7, 2022

Conversation

ghost
Copy link

@ghost ghost commented Jan 5, 2022

  • [×] Do only one thing
  • [×] Non breaking API changes
  • [×] Tested

What did this pull request do?

  • en : feat: add Connection to execute multiple commands in a single conn
  • zh : 支持一个 conn 内可以执行多个命令

User Case Description

func TestWithSingleConnection(t *testing.T) {

	var expectedName = "test"
	var actualName string

	setSQL, getSQL := getSetSQL(DB.Dialector.Name())
	if len(setSQL) == 0 || len(getSQL) == 0 {
		return
	}

	err := DB.Connection(func(tx *gorm.DB) error {
		if err := tx.Exec(setSQL, expectedName).Error; err != nil {
			return err
		}

		if err := tx.Raw(getSQL).Scan(&actualName).Error; err != nil {
			return err
		}
		return nil
	})

	if err != nil {
		t.Errorf(fmt.Sprintf("Connection should work, but got err %v", err))
	}

	if actualName != expectedName {
		t.Errorf("Connection() method should get correct value, expect: %v, got %v", expectedName, actualName)
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple commands in a single connection PostgreSQL RLS (Row level security)
2 participants