sqldb

package
v1.10.49 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IsIn    = "_IN_"
	BeginOp = "_BEGIN_"
	EndOp   = "_END"
	AndOp   = "_AND_"
	OrOp    = "_OR_"
	IsNull  = "_IS_NULL_"
)
View Source
const (
	FlagNameDbPingTimeout  = "db.ping.timeout"
	FlagNameDbQueryTimeout = "db.query.timeout"
	FlagNameDbMaxIdle      = "db.max.idle"
	FlagNameDbMaxOpen      = "db.max.open"
	FlagNameDbMaxLifetime  = "db.max.lifetime"
)

Variables

View Source
var (
	ErrModifiedID     = fmt.Errorf("not allowed modification of ID")
	ErrNotFound       = fmt.Errorf("record not found")
	ErrDuplicateFound = fmt.Errorf("duplicate record found")
)
View Source
var (
	FlagDbPingTimeout  = common.SystemFlagInt(FlagNameDbPingTimeout, 3*1000, "Database ping timeout")
	FlagDbQueryTimeout = common.SystemFlagInt(FlagNameDbQueryTimeout, 120*1000, "Database query timeout")
	FlagDbMaxIdle      = common.SystemFlagInt(FlagNameDbMaxIdle, 0, "Database max idle connections")
	FlagMaxOpen        = common.SystemFlagInt(FlagNameDbMaxOpen, 0, "Database max open connections")
	FlagMaxLifetime    = common.SystemFlagInt(FlagNameDbMaxLifetime, 0, "Database connection max lifetime")
)

Functions

func IsDuplicateKeyError added in v1.10.42

func IsDuplicateKeyError(err error) bool

func OrderByOp added in v1.10.42

func OrderByOp(fieldname string, ascending bool) string

func SelectOp added in v1.10.42

func SelectOp(fieldname ...string) string

func ToAny added in v1.10.42

func ToAny[T any](arrOrSingle T) []any

Types

type CRUD added in v1.10.42

type CRUD[T any] struct {
	Name       string
	Repository *Repository[T]
	URLPrefix  string
	PostURL    *common.RestURL
	ListURL    *common.RestURL
	GetURL     *common.RestURL
	PutURL     *common.RestURL
	DeleteURL  *common.RestURL
}

func NewCrud added in v1.10.42

func NewCrud[T any](crudHandlerFunc CRUDHandlerFunc, repository *Repository[T], basicAuth func(r *http.Request, username, password string) error, urlPrefix string) (*CRUD[T], error)

func (*CRUD[T]) DeleteHandler added in v1.10.42

func (crud *CRUD[T]) DeleteHandler(w http.ResponseWriter, r *http.Request)

func (*CRUD[T]) GetHandler added in v1.10.42

func (crud *CRUD[T]) GetHandler(w http.ResponseWriter, r *http.Request)

func (*CRUD[T]) ListHandler added in v1.10.42

func (crud *CRUD[T]) ListHandler(w http.ResponseWriter, r *http.Request)

func (*CRUD[T]) PostHandler added in v1.10.42

func (crud *CRUD[T]) PostHandler(w http.ResponseWriter, r *http.Request)

func (*CRUD[T]) PutHandler added in v1.10.42

func (crud *CRUD[T]) PutHandler(w http.ResponseWriter, r *http.Request)

type CRUDHandlerFunc added in v1.10.42

type CRUDHandlerFunc func(restURL *common.RestURL, description string, needsAuth bool, handler http.HandlerFunc)

type Field

type Field struct {
	Value  any  `json:"value"`
	IsNull bool `json:"isnull"`
}

func (Field) String

func (f Field) String() string

type FieldBool

type FieldBool struct {
	sql.NullBool
}

func NewFieldBool

func NewFieldBool(v ...bool) FieldBool

func (*FieldBool) Bool

func (c *FieldBool) Bool() bool

func (FieldBool) MarshalJSON

func (c FieldBool) MarshalJSON() ([]byte, error)

func (*FieldBool) SetBool

func (c *FieldBool) SetBool(v bool)

func (*FieldBool) SetNull

func (c *FieldBool) SetNull()

func (FieldBool) String

func (c FieldBool) String() string

func (*FieldBool) UnmarshalJSON

func (c *FieldBool) UnmarshalJSON(data []byte) error

type FieldInt64

type FieldInt64 struct {
	sql.NullInt64
}

func NewFieldInt64

func NewFieldInt64(v ...int64) FieldInt64

func (*FieldInt64) Int64

func (c *FieldInt64) Int64() int64

func (FieldInt64) MarshalJSON

func (c FieldInt64) MarshalJSON() ([]byte, error)

func (*FieldInt64) SetInt64

func (c *FieldInt64) SetInt64(v int64)

func (*FieldInt64) SetNull

func (c *FieldInt64) SetNull()

func (FieldInt64) String

func (c FieldInt64) String() string

func (*FieldInt64) UnmarshalJSON

func (c *FieldInt64) UnmarshalJSON(data []byte) error

type FieldString

type FieldString struct {
	sql.NullString
}

func NewFieldString

func NewFieldString(v ...string) FieldString

func (*FieldString) GetString

func (c *FieldString) GetString(v string)

func (FieldString) MarshalJSON

func (c FieldString) MarshalJSON() ([]byte, error)

func (*FieldString) SetField

func (c *FieldString) SetField(other FieldString)

func (*FieldString) SetNull

func (c *FieldString) SetNull()

func (*FieldString) SetString

func (c *FieldString) SetString(v string)

func (FieldString) String

func (c FieldString) String() string

func (*FieldString) UnmarshalJSON

func (c *FieldString) UnmarshalJSON(data []byte) error

type FieldTime

type FieldTime struct {
	sql.NullTime
}

func NewFieldTime

func NewFieldTime(v ...time.Time) FieldTime

func (FieldTime) MarshalJSON

func (c FieldTime) MarshalJSON() ([]byte, error)

func (*FieldTime) SetNull

func (c *FieldTime) SetNull()

func (*FieldTime) SetTime

func (c *FieldTime) SetTime(v time.Time)

func (FieldTime) String

func (c FieldTime) String() string

func (*FieldTime) Time

func (c *FieldTime) Time() time.Time

func (*FieldTime) UnmarshalJSON

func (c *FieldTime) UnmarshalJSON(data []byte) error

type Repository added in v1.10.42

type Repository[T any] struct {
	// contains filtered or unexported fields
}

func NewRepository added in v1.10.42

func NewRepository[T any](gorm *gorm.DB) (*Repository[T], error)

func (*Repository[T]) Delete added in v1.10.42

func (repository *Repository[T]) Delete(id int) error

func (*Repository[T]) Find added in v1.10.42

func (repository *Repository[T]) Find(id int) (*T, error)

func (*Repository[T]) FindAll added in v1.10.42

func (repository *Repository[T]) FindAll(offset int, limit int) ([]T, error)

func (*Repository[T]) FindFirst added in v1.10.42

func (repository *Repository[T]) FindFirst(where *WhereTerm) (*T, error)

func (*Repository[T]) Save added in v1.10.42

func (repository *Repository[T]) Save(record *T) error

func (*Repository[T]) SaveAll added in v1.10.42

func (repository *Repository[T]) SaveAll(records []T) error

func (*Repository[T]) Update added in v1.10.42

func (repository *Repository[T]) Update(record T) error

type Resultset

type Resultset struct {
	ColumnNames []string
	ColumnTypes []*sql.ColumnType
	RowCount    int
	Rows        any
}

func (*Resultset) FieldByIndex

func (rs *Resultset) FieldByIndex(row int, col int) Field

func (*Resultset) FieldByName

func (rs *Resultset) FieldByName(row int, fieldName string) Field

type ResultsetFunc

type ResultsetFunc func(rs *Resultset) error

type SqlDb

type SqlDb struct {
	Driver string
	DSN    string
	// contains filtered or unexported fields
}

func NewSqlDb

func NewSqlDb(driver, dsn string) (*SqlDb, error)

func (*SqlDb) Begin

func (sqlDb *SqlDb) Begin() error

func (*SqlDb) Close

func (sqlDb *SqlDb) Close() error

func (*SqlDb) Commit

func (sqlDb *SqlDb) Commit() error

func (*SqlDb) Execute

func (sqlDb *SqlDb) Execute(sqlcmd string, args ...any) (int64, error)

func (*SqlDb) Health

func (sqlDb *SqlDb) Health() error

func (*SqlDb) Init

func (sqlDb *SqlDb) Init(driver, dsn string) error

func (*SqlDb) Open

func (sqlDb *SqlDb) Open() error

func (*SqlDb) Query

func (sqlDb *SqlDb) Query(sqlcmd string, args ...any) (*Resultset, error)

func (*SqlDb) QueryPaged

func (sqlDb *SqlDb) QueryPaged(fn ResultsetFunc, pageRowCount int, sqlcmd string, args ...any) (int, error)

func (*SqlDb) Rollback

func (sqlDb *SqlDb) Rollback() error

type WhereItem added in v1.10.42

type WhereItem struct {
	Fieldname string
	Operator  string
	Value     any
}

func (WhereItem) Build added in v1.10.42

func (whereItem WhereItem) Build() (string, []any)

type WhereTerm added in v1.10.42

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

func NewWhereTerm added in v1.10.42

func NewWhereTerm() *WhereTerm

func (*WhereTerm) And added in v1.10.42

func (whereTerm *WhereTerm) And() *WhereTerm

func (*WhereTerm) Begin added in v1.10.42

func (whereTerm *WhereTerm) Begin() *WhereTerm

func (WhereTerm) Build added in v1.10.42

func (whereTerm WhereTerm) Build() (string, []any)

func (*WhereTerm) End added in v1.10.42

func (whereTerm *WhereTerm) End() *WhereTerm

func (*WhereTerm) Or added in v1.10.42

func (whereTerm *WhereTerm) Or() *WhereTerm

func (*WhereTerm) Where added in v1.10.42

func (whereTerm *WhereTerm) Where(whereItem WhereItem) *WhereTerm

Jump to

Keyboard shortcuts

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