clientx

package
v0.0.0-...-f75e619 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: Apache-2.0 Imports: 10 Imported by: 10

Documentation

Overview

Package clientx is ent client extension

Index

Constants

This section is empty.

Variables

View Source
var (
	ChangeSet *entcache.ChangeSet
)

Functions

func BuildEntCacheDriver

func BuildEntCacheDriver(cnf *conf.Configuration, preDriver dialect.Driver) (dialect.Driver, *entcache.ChangeSet)

BuildEntCacheDriver 构建ent缓存驱动.这里保证ChangeSet为第一次初始的单例值.

func WithTx

func WithTx(ctx context.Context, initTxFn Tx, fn func(itx Transactor) error) error

WithTx runs the given function in a transaction.If the function returns an error, the transaction is rolled back.

Example:

  WithTx(ctx, func(ctx context.Context) (clientx.Transactor, error) {
      return db.Tx(ctx) // db is *ent.Client
  }, func(itx clientx.Transactor) error {
	     tx := itx.(*ent.Tx)
      // do something with tx
  })

Types

type RouteDriver

type RouteDriver struct {
	// contains filtered or unexported fields
}

RouteDriver is a dialect.Driver that routes to different database instances based on the domain name.

func NewRouteDriver

func NewRouteDriver(cfg *conf.Configuration, opts ...RouteDriverOption) *RouteDriver

NewRouteDriver return a router driver from woocoo configuration

Example:

``` yaml store:

portal:
  driverName: mysql
  dsn: root:@tcp(localhost:3306)/portal?parseTime=true&loc=Local
  multiInstances:
    test.com:
      dsn: root:@tcp(localhost:3307)/portal?parseTime=true&loc=Local
    test.cn:
      driverName: mysql
      dsn: root:@tcp(localhost:3308)/portal?parseTime=true&loc=Local

```

func (*RouteDriver) BeginTx

func (r *RouteDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)

func (*RouteDriver) Close

func (r *RouteDriver) Close() error

func (*RouteDriver) Dialect

func (r *RouteDriver) Dialect() string

func (*RouteDriver) Exec

func (r *RouteDriver) Exec(ctx context.Context, query string, args, v any) error

func (*RouteDriver) Query

func (r *RouteDriver) Query(ctx context.Context, query string, args, v any) error

func (*RouteDriver) Tx

func (r *RouteDriver) Tx(ctx context.Context) (dialect.Tx, error)

type RouteDriverOption

type RouteDriverOption func(*RouteDriver)

type Transactor

type Transactor interface {
	Commit() error
	Rollback() error
}

Transactor is the interface that wraps the Commit and Rollback methods.

type Tx

type Tx func(ctx context.Context) (Transactor, error)

Jump to

Keyboard shortcuts

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