Documentation
¶
Index ¶
- func ExampleAuditHook(ctx *HookContext) error
- func ExampleCacheHook(ctx *HookContext) error
- func ExampleErrorHandlingHook(ctx *HookContext) error
- func ExampleLoggingHook(ctx *HookContext) error
- func ExampleQueryModificationHook(ctx *HookContext) error
- func ExampleResultFilterHook(ctx *HookContext) error
- func ExampleSecurityHook(ctx *HookContext) error
- func IsNumeric(s string) bool
- func RegisterSecurityHooks(handler *Handler, securityList *security.SecurityList)
- func ValidSQL(input, mode string) string
- type FilterOperator
- type HTTPFuncType
- type Handler
- func (h *Handler) ApplyDistinct(sqlQuery string, params *RequestParameters) string
- func (h *Handler) ApplyFieldSelection(sqlQuery string, params *RequestParameters) string
- func (h *Handler) ApplyFilters(sqlQuery string, params *RequestParameters) string
- func (h *Handler) GetDatabase() common.Database
- func (h *Handler) GetVariablesCallback() func(r *http.Request) map[string]interface{}
- func (h *Handler) Hooks() *HookRegistry
- func (h *Handler) ParseParameters(r *http.Request) *RequestParameters
- func (h *Handler) SetVariablesCallback(callback func(r *http.Request) map[string]interface{})
- func (h *Handler) SqlQuery(sqlquery string, options SqlQueryOptions) HTTPFuncType
- func (h *Handler) SqlQueryList(sqlquery string, options SqlQueryOptions) HTTPFuncType
- 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 RequestParameters
- type SqlQueryOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleAuditHook ¶
func ExampleAuditHook(ctx *HookContext) error
ExampleAuditHook logs all queries and results for audit purposes
func ExampleCacheHook ¶
func ExampleCacheHook(ctx *HookContext) error
ExampleCacheHook implements simple response caching
func ExampleErrorHandlingHook ¶
func ExampleErrorHandlingHook(ctx *HookContext) error
ExampleErrorHandlingHook provides custom error handling
func ExampleLoggingHook ¶
func ExampleLoggingHook(ctx *HookContext) error
ExampleLoggingHook logs all SQL queries before execution
func ExampleQueryModificationHook ¶
func ExampleQueryModificationHook(ctx *HookContext) error
ExampleQueryModificationHook modifies SQL queries to add user-specific filtering
func ExampleResultFilterHook ¶
func ExampleResultFilterHook(ctx *HookContext) error
ExampleResultFilterHook filters results after query execution
func ExampleSecurityHook ¶
func ExampleSecurityHook(ctx *HookContext) error
ExampleSecurityHook validates user permissions before executing queries
func RegisterSecurityHooks ¶ added in v0.0.67
func RegisterSecurityHooks(handler *Handler, securityList *security.SecurityList)
RegisterSecurityHooks registers security hooks for funcspec handlers Note: funcspec operates on SQL queries directly, so row-level security is not directly applicable We provide audit logging for data access tracking
Types ¶
type FilterOperator ¶
type FilterOperator struct {
Operator string // eq, neq, gt, lt, gte, lte, like, ilike, in, between, etc.
Value string
Logic string // AND or OR
}
FilterOperator represents a filter with operator
type HTTPFuncType ¶
type HTTPFuncType func(http.ResponseWriter, *http.Request)
HTTPFuncType is a function type for HTTP handlers
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles function-based SQL API requests
func NewHandler ¶
NewHandler creates a new function API handler
func (*Handler) ApplyDistinct ¶
func (h *Handler) ApplyDistinct(sqlQuery string, params *RequestParameters) string
ApplyDistinct adds DISTINCT to SQL query if requested
func (*Handler) ApplyFieldSelection ¶
func (h *Handler) ApplyFieldSelection(sqlQuery string, params *RequestParameters) string
ApplyFieldSelection applies column selection to SQL query
func (*Handler) ApplyFilters ¶
func (h *Handler) ApplyFilters(sqlQuery string, params *RequestParameters) string
ApplyFilters applies all filters to the SQL query
func (*Handler) GetDatabase ¶ added in v0.0.65
GetDatabase returns the underlying database connection Implements common.SpecHandler interface
func (*Handler) GetVariablesCallback ¶ added in v0.0.106
func (*Handler) Hooks ¶
func (h *Handler) Hooks() *HookRegistry
Hooks returns the hook registry for this handler Use this to register custom hooks for operations
func (*Handler) ParseParameters ¶
func (h *Handler) ParseParameters(r *http.Request) *RequestParameters
ParseParameters parses all parameters from request headers and query string
func (*Handler) SetVariablesCallback ¶ added in v0.0.106
func (*Handler) SqlQuery ¶
func (h *Handler) SqlQuery(sqlquery string, options SqlQueryOptions) HTTPFuncType
SqlQuery creates an HTTP handler that executes a SQL query and returns a single record
func (*Handler) SqlQueryList ¶
func (h *Handler) SqlQueryList(sqlquery string, options SqlQueryOptions) HTTPFuncType
SqlQueryList creates an HTTP handler that executes a SQL query and returns a list with pagination
type HookContext ¶
type HookContext struct {
Context context.Context
Handler *Handler // Reference to the handler for accessing database
Request *http.Request
Writer http.ResponseWriter
// SQL query and variables
SQLQuery string // The SQL query being executed (can be modified by hooks)
Variables map[string]interface{} // Variables extracted from request
InputVars []string // Input variable placeholders found in query
MetaInfo map[string]interface{} // Metadata about the request
PropQry map[string]string // Property query parameters
// User context
UserContext *security.UserContext
// Pagination and filtering (for list queries)
SortColumns string
Limit int
Offset int
// Results
Result interface{} // Query result (single record or list)
Total int64 // Total count (for list queries)
Error error // Error if operation failed
ComplexAPI bool // Whether complex API response format is requested
NoCount bool // Whether count query should be skipped
BlankParams bool // Whether blank parameters should be removed
AllowFilter bool // Whether filtering is allowed
// 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
}
HookContext contains all the data available to a hook
type HookFunc ¶
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 ¶
type HookRegistry struct {
// contains filtered or unexported fields
}
HookRegistry manages all registered hooks
func NewHookRegistry ¶
func NewHookRegistry() *HookRegistry
NewHookRegistry creates a new hook registry
func (*HookRegistry) Clear ¶
func (r *HookRegistry) Clear(hookType HookType)
Clear removes all hooks for the specified type
func (*HookRegistry) ClearAll ¶
func (r *HookRegistry) ClearAll()
ClearAll removes all registered hooks
func (*HookRegistry) Count ¶
func (r *HookRegistry) Count(hookType HookType) int
Count returns the number of hooks registered for a specific type
func (*HookRegistry) Execute ¶
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 ¶
func (r *HookRegistry) GetAllHookTypes() []HookType
GetAllHookTypes returns all hook types that have registered hooks
func (*HookRegistry) HasHooks ¶
func (r *HookRegistry) HasHooks(hookType HookType) bool
HasHooks returns true if there are any hooks registered for the specified type
func (*HookRegistry) Register ¶
func (r *HookRegistry) Register(hookType HookType, hook HookFunc)
Register adds a new hook for the specified hook type
func (*HookRegistry) RegisterMultiple ¶
func (r *HookRegistry) RegisterMultiple(hookTypes []HookType, hook HookFunc)
RegisterMultiple registers a hook for multiple hook types
type HookType ¶
type HookType string
HookType defines the type of hook to execute
const ( // Query operation hooks (for SqlQuery - single record) BeforeQuery HookType = "before_query" AfterQuery HookType = "after_query" // Query list operation hooks (for SqlQueryList - multiple records) BeforeQueryList HookType = "before_query_list" AfterQueryList HookType = "after_query_list" // SQL execution hooks (just before SQL is executed) BeforeSQLExec HookType = "before_sql_exec" AfterSQLExec HookType = "after_sql_exec" // Response hooks (before response is sent) BeforeResponse HookType = "before_response" )
type RequestParameters ¶
type RequestParameters struct {
// Field selection
SelectFields []string
NotSelectFields []string
Distinct bool
// Filtering
FieldFilters map[string]string // column -> value (exact match)
SearchFilters map[string]string // column -> value (ILIKE)
SearchOps map[string]FilterOperator // column -> {operator, value, logic}
CustomSQLWhere string
CustomSQLOr string
// Sorting & Pagination
SortColumns string
Limit int
Offset int
// Advanced features
SkipCount bool
SkipCache bool
// Response format
ResponseFormat string // "simple", "detail", "syncfusion"
ComplexAPI bool // true if NOT simple API
}
RequestParameters holds parsed parameters from headers and query string
type SqlQueryOptions ¶ added in v0.0.105
func NewSqlQueryOptions ¶ added in v0.0.106
func NewSqlQueryOptions() SqlQueryOptions