helper

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[Q chunkImp[Q, T], T any](ctx context.Context, query Q, chunk int, fn func(batchIndex int, items []*T) error) error

Chunk 分批处理数据 example:

client, err := ent.Open("mysql", os.Getenv("ACCOUNT_DB_DSN"))
if err != nil {
	panic(err)
}
ctx := context.Background()
err = enthelper.Chunk(ctx, client.Account.Query(), 100, func(batchIndex int, items []*ent.Account) error {
	for i, item := range items {
		fmt.Println(batch, i, item.Email)
	}
	return nil
})

func WithTx

func WithTx[Q clientImp[T], T txImp](ctx context.Context, client Q, fn func(ctx context.Context, tx T) error) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL