{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package funcspec\n\n## Functions\n\n```go\nfunc ExampleAuditHook(ctx *HookContext) error\n```\nExampleAuditHook logs all queries and results for audit purposes\n\n```go\nfunc ExampleCacheHook(ctx *HookContext) error\n```\nExampleCacheHook implements simple response caching\n\n```go\nfunc ExampleErrorHandlingHook(ctx *HookContext) error\n```\nExampleErrorHandlingHook provides custom error handling\n\n```go\nfunc ExampleLoggingHook(ctx *HookContext) error\n```\nExampleLoggingHook logs all SQL queries before execution\n\n```go\nfunc ExampleQueryModificationHook(ctx *HookContext) error\n```\nExampleQueryModificationHook modifies SQL queries to add user-specific filtering\n\n```go\nfunc ExampleResultFilterHook(ctx *HookContext) error\n```\nExampleResultFilterHook filters results after query execution\n\n```go\nfunc ExampleSecurityHook(ctx *HookContext) error\n```\nExampleSecurityHook validates user permissions before executing queries\n\n```go\nfunc IsNumeric(s string) bool\n```\nIsNumeric checks if a string contains only numeric characters\n\n```go\nfunc RegisterSecurityHooks(handler *Handler, securityList *security.SecurityList)\n```\nRegisterSecurityHooks registers security hooks for funcspec handlers Note: funcspec operates on SQL queries directly, so row-level security is not directly applicable We provide auth enforcement and audit logging for data access tracking\n\n```go\nfunc ValidSQL(input, mode string) string\n```\nValidSQL validates and sanitizes SQL input to prevent injection mode can be: \"colname\", \"colvalue\", \"select\"\n\n## Types\n\n```go\ntype FilterOperator struct {\n\tOperator string // eq, neq, gt, lt, gte, lte, like, ilike, in, between, etc.\n\tValue    string\n\tLogic    string // AND or OR\n}\n```\nFilterOperator represents a filter with operator\n\n```go\ntype HTTPFuncType func(http.ResponseWriter, *http.Request)\n```\nHTTPFuncType is a function type for HTTP handlers\n\n```go\ntype Handler struct {\n\t// contains filtered or unexported fields\n}\n```\nHandler handles function-based SQL API requests\n\n```go\nfunc NewHandler(db common.Database) *Handler\n```\nNewHandler creates a new function API handler\n\n```go\nfunc (h *Handler) ApplyDistinct(sqlQuery string, params *RequestParameters) string\n```\nApplyDistinct adds DISTINCT to SQL query if requested\n\n```go\nfunc (h *Handler) ApplyFieldSelection(sqlQuery string, params *RequestParameters) string\n```\nApplyFieldSelection applies column selection to SQL query\n\n```go\nfunc (h *Handler) ApplyFilters(sqlQuery string, params *RequestParameters) string\n```\nApplyFilters applies all filters to the SQL query\n\n```go\nfunc (h *Handler) GetDatabase() common.Database\n```\nGetDatabase returns the underlying database connection Implements common.SpecHandler interface\n\n```go\nfunc (h *Handler) GetVariablesCallback() func(r *http.Request) map[string]interface{}\n```\n\n```go\nfunc (h *Handler) Hooks() *HookRegistry\n```\nHooks returns the hook registry for this handler Use this to register custom hooks for operations\n\n```go\nfunc (h *Handler) ParseParameters(r *http.Request) *RequestParameters\n```\nParseParameters parses all parameters from request headers and query string\n\n```go\nfunc (h *Handler) SetVariablesCallback(callback func(r *http.Request) map[string]interface{})\n```\n\n```go\nfunc (h *Handler) SqlQuery(sqlquery string, options SqlQueryOptions) HTTPFuncType\n```\nSqlQuery creates an HTTP handler that executes a SQL query and returns a single record\n\n```go\nfunc (h *Handler) SqlQueryList(sqlquery string, options SqlQueryOptions) HTTPFuncType\n```\nSqlQueryList creates an HTTP handler that executes a SQL query and returns a list with pagination\n\n```go\ntype HookContext struct {\n\tContext context.Context\n\tHandler *Handler // Reference to the handler for accessing database\n\tRequest *http.Request\n\tWriter  http.ResponseWriter\n\n\t// SQL query and variables\n\tSQLQuery  string                 // The SQL query being executed (can be modified by hooks)\n\tVariables map[string]interface{} // Variables extracted from request\n\tInputVars []string               // Input variable placeholders found in query\n\tMetaInfo  map[string]interface{} // Metadata about the request\n\tPropQry   map[string]string      // Property query parameters\n\n\t// User context\n\tUserContext *security.UserContext\n\n\t// Tx provides access to the database/transaction for executing additional SQL\n\t// This allows hooks to run custom queries in addition to the main Query chain\n\tTx common.Database\n\n\t// Pagination and filtering (for list queries)\n\tSortColumns string\n\tLimit       int\n\tOffset      int\n\n\t// Results\n\tResult      interface{} // Query result (single record or list)\n\tTotal       int64       // Total count (for list queries)\n\tError       error       // Error if operation failed\n\tComplexAPI  bool        // Whether complex API response format is requested\n\tNoCount     bool        // Whether count query should be skipped\n\tBlankParams bool        // Whether blank parameters should be removed\n\tAllowFilter bool        // Whether filtering is allowed\n\n\t// Allow hooks to abort the operation\n\tAbort        bool   // If set to true, the operation will be aborted\n\tAbortMessage string // Message to return if aborted\n\tAbortCode    int    // HTTP status code if aborted\n}\n```\nHookContext contains all the data available to a hook\n\n```go\nfunc (c *HookContext) SetTx(tx common.Database)\n```\nSetTx points the context at the transaction in use (common.TxContext).\n\n```go\ntype HookFunc func(*HookContext) error\n```\nHookFunc 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\n\n```go\ntype HookRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nHookRegistry manages all registered hooks\n\n```go\nfunc NewHookRegistry() *HookRegistry\n```\nNewHookRegistry creates a new hook registry\n\n```go\nfunc (r *HookRegistry) Clear(hookType HookType)\n```\nClear removes all hooks for the specified type\n\n```go\nfunc (r *HookRegistry) ClearAll()\n```\nClearAll removes all registered hooks\n\n```go\nfunc (r *HookRegistry) Count(hookType HookType) int\n```\nCount returns the number of hooks registered for a specific type\n\n```go\nfunc (r *HookRegistry) Execute(hookType HookType, ctx *HookContext) error\n```\nExecute runs all hooks for the specified type in order If any hook returns an error, execution stops and the error is returned\n\n```go\nfunc (r *HookRegistry) ExecuteBeforeOp(hookType HookType, ctx *HookContext) error\n```\nExecuteBeforeOp executes the BeforeOp hook followed by the given SQL-operation hook (BeforeQuery, BeforeQueryList, or BeforeSQLExec). BeforeOp always runs first so it can observe/veto every SQL operation regardless of type.\n\n```go\nfunc (r *HookRegistry) GetAllHookTypes() []HookType\n```\nGetAllHookTypes returns all hook types that have registered hooks\n\n```go\nfunc (r *HookRegistry) HasHooks(hookType HookType) bool\n```\nHasHooks returns true if there are any hooks registered for the specified type\n\n```go\nfunc (r *HookRegistry) Register(hookType HookType, hook HookFunc)\n```\nRegister adds a new hook for the specified hook type\n\n```go\nfunc (r *HookRegistry) RegisterMultiple(hookTypes []HookType, hook HookFunc)\n```\nRegisterMultiple registers a hook for multiple hook types\n\n```go\ntype HookType string\n```\nHookType defines the type of hook to execute\n\n```go\nconst (\n\t// Query operation hooks (for SqlQuery - single record)\n\tBeforeQuery HookType = \"before_query\"\n\tAfterQuery  HookType = \"after_query\"\n\n\t// Query list operation hooks (for SqlQueryList - multiple records)\n\tBeforeQueryList HookType = \"before_query_list\"\n\tAfterQueryList  HookType = \"after_query_list\"\n\n\t// SQL execution hooks (just before SQL is executed)\n\tBeforeSQLExec HookType = \"before_sql_exec\"\n\tAfterSQLExec  HookType = \"after_sql_exec\"\n\n\t// Response hooks (before response is sent)\n\tBeforeResponse HookType = \"before_response\"\n\n\t// BeforeOp fires immediately before every SQL operation (query, query list, SQL exec).\n\t// It fires at each individual SQL-operation hook point, so it runs once per statement executed.\n\tBeforeOp HookType = \"before_op\"\n\n\t// OnTxBegin fires once, first, inside every transaction the handler opens\n\t// (the main transaction and the short one that runs BeforeResponse).\n\t// hookCtx.Tx is the transaction; use it to stamp transaction-local state such\n\t// as RLS settings. An error or abort rolls the transaction back.\n\tOnTxBegin HookType = common.TxHookName\n)\n```\n\n```go\ntype RequestParameters struct {\n\t// Field selection\n\tSelectFields    []string\n\tNotSelectFields []string\n\tDistinct        bool\n\n\t// Filtering\n\tFieldFilters   map[string]string         // column -\u003e value (exact match)\n\tSearchFilters  map[string]string         // column -\u003e value (ILIKE)\n\tSearchOps      map[string]FilterOperator // column -\u003e {operator, value, logic}\n\tCustomSQLWhere string\n\tCustomSQLOr    string\n\n\t// Sorting \u0026 Pagination\n\tSortColumns string\n\tLimit       int\n\tOffset      int\n\n\t// Advanced features\n\tSkipCount bool\n\tSkipCache bool\n\n\t// Response format\n\tResponseFormat string // \"simple\", \"detail\", \"syncfusion\"\n\tComplexAPI     bool   // true if NOT simple API\n}\n```\nRequestParameters holds parsed parameters from headers and query string\n\n```go\ntype SqlQueryOptions struct {\n\tNoCount     bool\n\tBlankParams bool\n\tAllowFilter bool\n}\n```\n\n```go\nfunc NewSqlQueryOptions() SqlQueryOptions\n```\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/funcspec","name":"funcspec","synopsis":"","isRedistributable":true}
