Documentation
¶
Index ¶
- Constants
- Variables
- func IsDuplicateKeyError(err error) bool
- func OrderByOp(fieldname string, ascending bool) string
- func SelectOp(fieldname ...string) string
- func ToAny[T any](arrOrSingle T) []any
- type CRUD
- func (crud *CRUD[T]) DeleteHandler(w http.ResponseWriter, r *http.Request)
- func (crud *CRUD[T]) GetHandler(w http.ResponseWriter, r *http.Request)
- func (crud *CRUD[T]) ListHandler(w http.ResponseWriter, r *http.Request)
- func (crud *CRUD[T]) PostHandler(w http.ResponseWriter, r *http.Request)
- func (crud *CRUD[T]) PutHandler(w http.ResponseWriter, r *http.Request)
- type CRUDHandlerFunc
- type Field
- type FieldBool
- type FieldInt64
- type FieldString
- func (c *FieldString) GetString(v string)
- func (c FieldString) MarshalJSON() ([]byte, error)
- func (c *FieldString) SetField(other FieldString)
- func (c *FieldString) SetNull()
- func (c *FieldString) SetString(v string)
- func (c FieldString) String() string
- func (c *FieldString) UnmarshalJSON(data []byte) error
- type FieldTime
- type Repository
- func (repository *Repository[T]) Delete(id int) error
- func (repository *Repository[T]) Find(id int) (*T, error)
- func (repository *Repository[T]) FindAll(offset int, limit int) ([]T, error)
- func (repository *Repository[T]) FindFirst(where *WhereTerm) (*T, error)
- func (repository *Repository[T]) Save(record *T) error
- func (repository *Repository[T]) SaveAll(records []T) error
- func (repository *Repository[T]) Update(record T) error
- type Resultset
- type ResultsetFunc
- type SqlDb
- func (sqlDb *SqlDb) Begin() error
- func (sqlDb *SqlDb) Close() error
- func (sqlDb *SqlDb) Commit() error
- func (sqlDb *SqlDb) Execute(sqlcmd string, args ...any) (int64, error)
- func (sqlDb *SqlDb) Health() error
- func (sqlDb *SqlDb) Init(driver, dsn string) error
- func (sqlDb *SqlDb) Open() error
- func (sqlDb *SqlDb) Query(sqlcmd string, args ...any) (*Resultset, error)
- func (sqlDb *SqlDb) QueryPaged(fn ResultsetFunc, pageRowCount int, sqlcmd string, args ...any) (int, error)
- func (sqlDb *SqlDb) Rollback() error
- type WhereItem
- type WhereTerm
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
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 FieldBool ¶
func NewFieldBool ¶
func (FieldBool) MarshalJSON ¶
func (*FieldBool) UnmarshalJSON ¶
type FieldInt64 ¶
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 ¶
func NewFieldTime ¶
func (FieldTime) MarshalJSON ¶
func (*FieldTime) UnmarshalJSON ¶
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 }
type ResultsetFunc ¶
type SqlDb ¶
func (*SqlDb) QueryPaged ¶
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
Click to show internal directories.
Click to hide internal directories.