github.com/mailru/activerecord@v1.12.2/pkg/tarantool/connection.go (about)

     1  package tarantool
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/mailru/activerecord/pkg/activerecord"
     8  	"github.com/tarantool/go-tarantool"
     9  )
    10  
    11  var DefaultConnectionParams = activerecord.MapGlobParam{
    12  	Timeout: DefaultConnectionTimeout,
    13  }
    14  
    15  type Connection struct {
    16  	*tarantool.Connection
    17  	opts *ConnectionOptions
    18  }
    19  
    20  func GetConnection(_ context.Context, opts *ConnectionOptions) (*Connection, error) {
    21  	conn, err := tarantool.Connect(opts.server, opts.cfg)
    22  	if err != nil {
    23  		return nil, fmt.Errorf("error connect to tarantool %s with connect timeout '%d': %s", opts.server, opts.cfg.Timeout, err)
    24  	}
    25  
    26  	return &Connection{
    27  		Connection: conn,
    28  		opts:       opts,
    29  	}, nil
    30  }
    31  
    32  func (c *Connection) InstanceMode() any {
    33  	return c.opts.InstanceMode()
    34  }
    35  
    36  func (c *Connection) Close() {
    37  	if err := c.Connection.Close(); err != nil {
    38  		panic(err)
    39  	}
    40  
    41  }
    42  
    43  func (c *Connection) Done() <-chan struct{} {
    44  	return nil
    45  }
    46  
    47  func (c *Connection) Info() string {
    48  	return fmt.Sprintf("Server: %s, timeout; %d, user: %s", c.opts.server, c.opts.cfg.Timeout, c.opts.cfg.User)
    49  }