func (c *Client) Tx(ctx context.Context) (*Tx, error) {
	if _, ok := c.driver.(*txDriver); ok {
		return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
	}
	tx, err := newTx(ctx, c.driver)
	if err != nil {
		return nil, fmt.Errorf("ent: starting a transaction: %w", err)
	}
	cfg := c.config
	cfg.driver = tx
	return &Tx{
		ctx:    ctx,
		config: cfg,
		Beer:   NewBeerClient(cfg),
	}, nil
}
Tx returns a new transactional client. The provided context
is used until the transaction is committed or rolled back.
package ent
import (
	"context"
	"fmt"
	"log"
	"github.com/go-kratos/beer-shop/app/catalog/service/internal/data/ent/migrate"
	"github.com/go-kratos/beer-shop/app/catalog/service/internal/data/ent/beer"
	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
)
type Client struct {
	config
	Schema *migrate.Schema
	Beer *BeerClient
}
func NewClient(opts ...Option) *Client {
	cfg := config{log: log.Println, hooks: &hooks{}}
	cfg.options(opts...)
	client := &Client{config: cfg}
	client.init()
	return client
}
func (c *Client) init() {
	c.Schema = migrate.NewSchema(c.driver)
	c.Beer = NewBeerClient(c.config)
}
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
	switch driverName {
	case dialect.MySQL, dialect.Postgres, dialect.SQLite:
		drv, err := sql.Open(driverName, dataSourceName)
		if err != nil {
			return nil, err
		}
		return NewClient(append(options, Driver(drv))...), nil
	default:
		return nil, fmt.Errorf("unsupported driver: %q", driverName)
	}
}