github.com/blend/go-sdk@v1.20220411.3/db/dbutil/base_manager.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package dbutil
     9  
    10  import (
    11  	"context"
    12  
    13  	"github.com/blend/go-sdk/db"
    14  )
    15  
    16  // NewBaseManager creates a new manager.
    17  func NewBaseManager(conn *db.Connection, opts ...db.InvocationOption) BaseManager {
    18  	return BaseManager{
    19  		Conn:    conn,
    20  		Options: opts,
    21  	}
    22  }
    23  
    24  // BaseManager is the manager for database tasks.
    25  //
    26  // It is a base type you can use to build your own models
    27  // that provides an `Invoke` method that will add default
    28  // invocation options to a given invocation.
    29  type BaseManager struct {
    30  	Conn    *db.Connection
    31  	Options []db.InvocationOption
    32  }
    33  
    34  // Invoke runs a command with a given set of options merged with the manager defaults.
    35  func (m BaseManager) Invoke(ctx context.Context, opts ...db.InvocationOption) *db.Invocation {
    36  	return m.Conn.Invoke(append(m.Options, append(opts, db.OptContext(ctx))...)...)
    37  }