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

Does beego/orm support single-batch transactions? #5597

Open
PenguinLeee opened this issue Feb 21, 2024 · 1 comment
Open

Does beego/orm support single-batch transactions? #5597

PenguinLeee opened this issue Feb 21, 2024 · 1 comment

Comments

@PenguinLeee
Copy link

  1. What version of Go and beego are you using (bee version)?

go1.21.6, beegov2.1.6

  1. What operating system and processor architecture are you using (go env)?

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.6'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1461063096=/tmp/go-build -gno-record-gcc-switches'

  1. What did you do?

I am trying to manipulate RQLite through beego/orm. I

  • add the blank import _ "github.com/rqlite/gorqlite/stdlib"
  • excute orm.RegisterDataBase("default", "rqlite", "http://127.0.0.1:4001/?charset=utf8")
    and it works fine with simple CRUD operations.

However, RQLite supports transactions only in a single batch. One can group many statements into a single transaction, but one must submit them as a single unit. One cannot start a transaction, send some statements, come back later and submit some more, and then later commit.

I noticed that beego/orm supports 2 kinds of transactions, the first is:

        // Beego will manage the transaction's lifecycle
	// if the @param task return error, the transaction will be rollback
	// or the transaction will be committed
	err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
		// data
		user := new(User)
		user.Name = "test_transaction"

		// insert data
		// Using txOrm to execute SQL
		_, e := txOrm.Insert(user)
		// if e != nil the transaction will be rollback
		// or it will be committed
		return e
	})

and the second is through classic Begin(), Commit() and Rollback() (which is not supported by RQLite).

I wonder whether the single-batch transaction is supported and if supported, how to realize it through beego/orm?

@flycash
Copy link
Collaborator

flycash commented Apr 6, 2024

sorry, I don't know much about the RQLite. But if the RQLite already provide similar transaction like MySQL, beego/orm support it.

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

No branches or pull requests

2 participants