my

package
v0.3.24 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package my contains the Request object

Index

Constants

View Source
const (
	OK200  int = http.StatusOK                  // OK
	OK201  int = http.StatusCreated             // Created
	Err400 int = http.StatusBadRequest          // Client-Side Error
	Err401 int = http.StatusUnauthorized        // Unauthenticated
	Err403 int = http.StatusForbidden           // Unauthorized
	Err404 int = http.StatusNotFound            // Not Found
	Err429 int = http.StatusTooManyRequests     // Rate Limiting
	Err500 int = http.StatusInternalServerError // Server-Side Error
)
View Source
const MainDB string = "main"

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

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

Instance type stores the db connection pools for requests

func NewInstance

func NewInstance(p *db.ConnParams) (*Instance, error)

NewInstance creates a new Instance object

func (*Instance) AddConnection

func (i *Instance) AddConnection(name string, p *db.ConnParams) error

AddConnection adds a custom DB connection

func (*Instance) NewRequest

func (i *Instance) NewRequest(name string, args ...any) (*Request, error)

NewRequest creates a new Request

func (*Instance) NewRequestAt

func (i *Instance) NewRequestAt(key, name string, args ...any) (*Request, error)

NewRequestAt creates a new Request at custom db

type Request

type Request struct {
	Task
	Name    string
	Params  dict.Object
	DB      db.Conn
	Tx      db.Tx
	Checker qb.ResultChecker
	Status  int
	Now     clock.DateTime
	// contains filtered or unexported fields
}

Request is an application request that holds a DB connection, a transaction, result checker, transaction queries, request start time, and logs

func (*Request) AddDB added in v0.3.14

func (rq *Request) AddDB(key string) bool

AddDB adds a database connection to the request

func (*Request) AddDurationLog

func (rq *Request) AddDurationLog(start time.Time)

AddDurationLog adds a duration log message to the request

func (*Request) AddErrorLog

func (rq *Request) AddErrorLog(err error)

AddErrorLog adds an error log message to the request

func (*Request) AddFmtLog

func (rq *Request) AddFmtLog(format string, args ...any)

AddFmtLog adds a formatted log message to the request

func (*Request) AddLog

func (rq *Request) AddLog(message string)

AddLog adds a log message to the request

func (*Request) AddTxStep

func (rq *Request) AddTxStep(q qb.Query)

AddTxStep adds a transaction step to the request

func (*Request) CommitTransaction

func (rq *Request) CommitTransaction() error

CommitTransaction commits the database transaction

func (*Request) ExpectAffected added in v0.3.24

func (rq *Request) ExpectAffected(count int)

ExpectAffected adds a AssertRowsAffected checker to the transaction

func (*Request) Fail

func (rq *Request) Fail(status int, message string, args ...any)

Fail adds an log message and sets the status of the request

func (*Request) MergeLogs

func (rq *Request) MergeLogs(srq *Request)

MergeLogs performs a concurrent-safe merging of subrequest logs to main request logs

func (*Request) Output

func (rq *Request) Output() string

Output combines the logs into a single string separated by newline

func (*Request) SetNow

func (rq *Request) SetNow() clock.DateTime

SetNow sets the Request.Now field

func (*Request) StartTransaction

func (rq *Request) StartTransaction(numSteps int) error

StartTransaction starts a database transaction

func (*Request) SubRequest

func (rq *Request) SubRequest() *Request

SubRequest creates a sub-request for concurrent tasks

func (*Request) SwitchDB added in v0.3.14

func (rq *Request) SwitchDB(key string) bool

SwitchDB changes the database connection of the request

type Task

type Task struct {
	Action string
	Target string
}

Task contains the Action and Target of the task

func (Task) String

func (t Task) String() string

String returns the string representation of the task

Jump to

Keyboard shortcuts

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