package
0.0.63
Repository: https://github.com/boostgo/lite.git
Documentation: pkg.go.dev

# README

storage

Connections

One line connects

sqlConn := sql.MustConnect("...")
mongoConn := mongo.Must(ctx, "", "", "localhost", 27017)

Transactor

Transactor - client which helps run transactions on abstract level.
In business logic layer (usecase, service) we can use transactor and not define which database is using (sql or mongo, whatever)

// initialize transactor
transactor := sql.NewTransactor(conn)

// wrap context with "transaction" key, then database clients will run queries by transaction
var err error
ctx, err = transactor.BeginCtx(ctx)
if err != nil {
    return err
}

// catch error and choose: rollback & commit transaction
defer func() {
    if err != nil {
        _ = transactor.RollbackCtx(ctx)
        return
    }

    _ = transactor.CommitCtx(ctx)
}()

Logging

Running queries by client (sql, mongo, etc...) can log queries with their params
Logging must be enabled at initializing client:

func NewUserRepository(conn *sqlx.DB) *UserRepo {
	const enableLog = true
	return &UserRepo{
		conn: sql.Client(conn, enableLog),
	}
}

It is possible turn off logging for certain calls by providing certain "context":

ctx = storage.NoLog(ctx)
users, err := userRepo.Get(ctx)
// ...

Also, we can check if method going to log

if storage.IsNoLog(ctx) {
	fmt.Println("no storage logging")
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

IsNoLog checks if context contain "no log" key.
NoLog set to context "no log" key.
RewriteTx take transaction key from original context and copy key to toCopy context.

# Constants

No description provided by the author

# Variables

ErrConnNotSelected returns if "shard client" does not choose connection to use.

# Interfaces

Transaction interface using by Transactor.
Transactor is common representation of transactions for any type of database.