Documentation
¶
Index ¶
- func ExampleBunRouterWithBunDB(bunDB *bun.DB)
- func ExampleWithBun(bunDB *bun.DB)
- func ExampleWithBunRouter(bunDB *bun.DB)
- func ExampleWithGORM(db *gorm.DB)
- func GetCursorFilter(tableName string, pkName string, modelColumns []string, ...) (string, error)
- func GetEntity(ctx context.Context) string
- func GetModel(ctx context.Context) interface{}
- func GetModelPtr(ctx context.Context) interface{}
- func GetSchema(ctx context.Context) string
- func GetTableName(ctx context.Context) string
- func NewStandardBunRouter() *router.StandardBunRouterAdapter
- func NewStandardMuxRouter() *router.StandardMuxAdapter
- func RegisterSecurityHooks(handler *Handler, securityList *security.SecurityList)
- func SetupBunRouterRoutes(bunRouter *router.StandardBunRouterAdapter, handler *Handler)
- func SetupMuxRoutes(muxRouter *mux.Router, handler *Handler, authMiddleware MiddlewareFunc)
- func WithEntity(ctx context.Context, entity string) context.Context
- func WithModel(ctx context.Context, model interface{}) context.Context
- func WithModelPtr(ctx context.Context, modelPtr interface{}) context.Context
- func WithRequestData(ctx context.Context, schema, entity, tableName string, ...) context.Context
- func WithSchema(ctx context.Context, schema string) context.Context
- func WithTableName(ctx context.Context, tableName string) context.Context
- type CursorDirection
- type FallbackHandler
- type GormTableCRUDRequest
- type GormTableNameInterface
- type GormTableSchemaInterface
- type Handler
- func (h *Handler) GetDatabase() common.Database
- func (h *Handler) GetRelationshipInfo(modelType reflect.Type, relationName string) *common.RelationshipInfo
- func (h *Handler) Handle(w common.ResponseWriter, r common.Request, params map[string]string)
- func (h *Handler) HandleGet(w common.ResponseWriter, r common.Request, params map[string]string)
- func (h *Handler) HandleOpenAPI(w common.ResponseWriter, r common.Request)
- func (h *Handler) Hooks() *HookRegistry
- func (h *Handler) RegisterModel(schema, name string, model interface{}) error
- func (h *Handler) SetFallbackHandler(fallback FallbackHandler)
- func (h *Handler) SetOpenAPIGenerator(generator func() (string, error))
- type HookContext
- type HookFunc
- type HookRegistry
- func (r *HookRegistry) Clear(hookType HookType)
- func (r *HookRegistry) ClearAll()
- func (r *HookRegistry) Count(hookType HookType) int
- func (r *HookRegistry) Execute(hookType HookType, ctx *HookContext) error
- func (r *HookRegistry) GetAllHookTypes() []HookType
- func (r *HookRegistry) HasHooks(hookType HookType) bool
- func (r *HookRegistry) Register(hookType HookType, hook HookFunc)
- func (r *HookRegistry) RegisterMultiple(hookTypes []HookType, hook HookFunc)
- type HookType
- type MiddlewareFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleBunRouterWithBunDB ¶
ExampleBunRouterWithBunDB shows the full uptrace stack (bunrouter + Bun ORM)
func ExampleWithBun ¶
ExampleWithBun shows how to switch to Bun ORM
func ExampleWithBunRouter ¶
ExampleWithBunRouter shows how to use bunrouter from uptrace
func ExampleWithGORM ¶
ExampleWithGORM shows how to use ResolveSpec with GORM
func GetCursorFilter ¶ added in v0.0.80
func GetCursorFilter( tableName string, pkName string, modelColumns []string, options common.RequestOptions, ) (string, error)
GetCursorFilter generates a SQL `EXISTS` subquery for cursor-based pagination. It uses the current request's sort and cursor values.
Parameters:
- tableName: name of the main table (e.g. "posts")
- pkName: primary key column (e.g. "id")
- modelColumns: optional list of valid main-table columns (for validation). Pass nil to skip.
- options: the request options containing sort and cursor information
Returns SQL snippet to embed in WHERE clause.
func GetModelPtr ¶
GetModelPtr retrieves model pointer from context
func GetTableName ¶
GetTableName retrieves table name from context
func NewStandardBunRouter ¶
func NewStandardBunRouter() *router.StandardBunRouterAdapter
NewStandardBunRouter creates a router with standard BunRouter handlers
func NewStandardMuxRouter ¶
func NewStandardMuxRouter() *router.StandardMuxAdapter
NewStandardMuxRouter creates a router with standard Mux HTTP handlers
func RegisterSecurityHooks ¶ added in v0.0.67
func RegisterSecurityHooks(handler *Handler, securityList *security.SecurityList)
RegisterSecurityHooks registers all security-related hooks with the handler
func SetupBunRouterRoutes ¶
func SetupBunRouterRoutes(bunRouter *router.StandardBunRouterAdapter, handler *Handler)
SetupBunRouterRoutes sets up bunrouter routes for the ResolveSpec API
func SetupMuxRoutes ¶
func SetupMuxRoutes(muxRouter *mux.Router, handler *Handler, authMiddleware MiddlewareFunc)
SetupMuxRoutes sets up routes for the ResolveSpec API with Mux authMiddleware is optional - if provided, routes will be protected with the middleware Example: SetupMuxRoutes(router, handler, func(h http.Handler) http.Handler { return security.NewAuthHandler(securityList, h) })
func WithEntity ¶
WithEntity adds entity to context
func WithModelPtr ¶
WithModelPtr adds model pointer to context
func WithRequestData ¶
func WithRequestData(ctx context.Context, schema, entity, tableName string, model, modelPtr interface{}) context.Context
WithRequestData adds all request-scoped data to context at once
func WithSchema ¶
WithSchema adds schema to context
Types ¶
type CursorDirection ¶ added in v0.0.80
type CursorDirection int
CursorDirection defines pagination direction
const ( CursorForward CursorDirection = 1 CursorBackward CursorDirection = -1 )
type FallbackHandler ¶ added in v0.0.69
FallbackHandler is a function that handles requests when no model is found It receives the same parameters as the Handle method
type GormTableCRUDRequest ¶
type GormTableCRUDRequest struct {
Request *string `json:"_request"`
}
func (GormTableCRUDRequest) GetRequest ¶
func (r GormTableCRUDRequest) GetRequest() string
func (*GormTableCRUDRequest) SetRequest ¶
func (r *GormTableCRUDRequest) SetRequest(request string)
type GormTableNameInterface ¶
type GormTableNameInterface interface {
TableName() string
}
Legacy interfaces for backward compatibility
type GormTableSchemaInterface ¶
type GormTableSchemaInterface interface {
TableSchema() string
}
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles API requests using database and model abstractions
func NewHandler ¶
func NewHandler(db common.Database, registry common.ModelRegistry) *Handler
NewHandler creates a new API handler with database and registry abstractions
func NewHandlerWithBun ¶
NewHandlerWithBun creates a new Handler with Bun adapter
func NewHandlerWithGORM ¶
NewHandlerWithGORM creates a new Handler with GORM adapter
func (*Handler) GetDatabase ¶ added in v0.0.65
GetDatabase returns the underlying database connection Implements common.SpecHandler interface
func (*Handler) GetRelationshipInfo ¶ added in v0.0.20
func (h *Handler) GetRelationshipInfo(modelType reflect.Type, relationName string) *common.RelationshipInfo
GetRelationshipInfo implements common.RelationshipInfoProvider interface
func (*Handler) HandleOpenAPI ¶ added in v0.0.87
func (h *Handler) HandleOpenAPI(w common.ResponseWriter, r common.Request)
HandleOpenAPI generates and returns the OpenAPI specification
func (*Handler) Hooks ¶ added in v0.0.67
func (h *Handler) Hooks() *HookRegistry
Hooks returns the hook registry for this handler Use this to register custom hooks for operations
func (*Handler) RegisterModel ¶
RegisterModel allows registering models at runtime
func (*Handler) SetFallbackHandler ¶ added in v0.0.69
func (h *Handler) SetFallbackHandler(fallback FallbackHandler)
SetFallbackHandler sets a fallback handler to be called when no model is found If not set, the handler will simply return (pass through to next route)
func (*Handler) SetOpenAPIGenerator ¶ added in v0.0.87
SetOpenAPIGenerator sets the OpenAPI generator function
type HookContext ¶ added in v0.0.67
type HookContext struct {
Context context.Context
Handler *Handler // Reference to the handler for accessing database, registry, etc.
Schema string
Entity string
Model interface{}
Options common.RequestOptions
Writer common.ResponseWriter
Request common.Request
// Operation-specific fields
ID string
Data interface{} // For create/update operations
Result interface{} // For after hooks
Error error // For after hooks
// Query chain - allows hooks to modify the query before execution
Query common.SelectQuery
// Allow hooks to abort the operation
Abort bool // If set to true, the operation will be aborted
AbortMessage string // Message to return if aborted
AbortCode int // HTTP status code if aborted
// Tx provides access to the database/transaction for executing additional SQL
// This allows hooks to run custom queries in addition to the main Query chain
Tx common.Database
}
HookContext contains all the data available to a hook
type HookFunc ¶ added in v0.0.67
type HookFunc func(*HookContext) error
HookFunc is the signature for hook functions It receives a HookContext and can modify it or return an error If an error is returned, the operation will be aborted
type HookRegistry ¶ added in v0.0.67
type HookRegistry struct {
// contains filtered or unexported fields
}
HookRegistry manages all registered hooks
func NewHookRegistry ¶ added in v0.0.67
func NewHookRegistry() *HookRegistry
NewHookRegistry creates a new hook registry
func (*HookRegistry) Clear ¶ added in v0.0.67
func (r *HookRegistry) Clear(hookType HookType)
Clear removes all hooks for the specified type
func (*HookRegistry) ClearAll ¶ added in v0.0.67
func (r *HookRegistry) ClearAll()
ClearAll removes all registered hooks
func (*HookRegistry) Count ¶ added in v0.0.67
func (r *HookRegistry) Count(hookType HookType) int
Count returns the number of hooks registered for a specific type
func (*HookRegistry) Execute ¶ added in v0.0.67
func (r *HookRegistry) Execute(hookType HookType, ctx *HookContext) error
Execute runs all hooks for the specified type in order If any hook returns an error, execution stops and the error is returned
func (*HookRegistry) GetAllHookTypes ¶ added in v0.0.67
func (r *HookRegistry) GetAllHookTypes() []HookType
GetAllHookTypes returns all hook types that have registered hooks
func (*HookRegistry) HasHooks ¶ added in v0.0.67
func (r *HookRegistry) HasHooks(hookType HookType) bool
HasHooks returns true if there are any hooks registered for the specified type
func (*HookRegistry) Register ¶ added in v0.0.67
func (r *HookRegistry) Register(hookType HookType, hook HookFunc)
Register adds a new hook for the specified hook type
func (*HookRegistry) RegisterMultiple ¶ added in v0.0.67
func (r *HookRegistry) RegisterMultiple(hookTypes []HookType, hook HookFunc)
RegisterMultiple registers a hook for multiple hook types
type HookType ¶ added in v0.0.67
type HookType string
HookType defines the type of hook to execute
const ( // Read operation hooks BeforeRead HookType = "before_read" AfterRead HookType = "after_read" // Create operation hooks BeforeCreate HookType = "before_create" AfterCreate HookType = "after_create" // Update operation hooks BeforeUpdate HookType = "before_update" AfterUpdate HookType = "after_update" // Delete operation hooks BeforeDelete HookType = "before_delete" AfterDelete HookType = "after_delete" // Scan/Execute operation hooks (for query building) BeforeScan HookType = "before_scan" )