Documentation
¶
Index ¶
- func QuoteIdent(qualifier string) string
- func QuoteLiteral(value string) string
- func ShouldUseNestedProcessor(data map[string]interface{}, model interface{}, ...) bool
- type APIError
- type CRUDRequestProvider
- type Column
- type ColumnValidator
- func (v *ColumnValidator) FilterRequestOptions(options RequestOptions) RequestOptions
- func (v *ColumnValidator) FilterValidColumns(columns []string) []string
- func (v *ColumnValidator) GetValidColumns() []string
- func (v *ColumnValidator) IsValidColumn(column string) bool
- func (v *ColumnValidator) ValidateColumn(column string) error
- func (v *ColumnValidator) ValidateColumns(columns []string) error
- func (v *ColumnValidator) ValidateRequestOptions(options RequestOptions) error
- type ComputedColumn
- type CustomOperator
- type Database
- type DeleteQuery
- type FilterOption
- type HTTPHandlerFunc
- type InsertQuery
- type Metadata
- type ModelRegistry
- type NestedCUDProcessor
- type Parameter
- type PreloadOption
- type PrimaryKeyNameProvider
- type ProcessResult
- type RelationshipInfo
- type RelationshipInfoProvider
- type Request
- type RequestBody
- type RequestOptions
- type Response
- type ResponseWriter
- type Result
- type RouteRegistration
- type Router
- type SchemaProvider
- type SelectQuery
- type SortOption
- type TableAliasProvider
- type TableMetadata
- type TableNameProvider
- type UpdateQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QuoteIdent ¶ added in v0.0.23
func QuoteLiteral ¶ added in v0.0.23
func ShouldUseNestedProcessor ¶ added in v0.0.20
func ShouldUseNestedProcessor(data map[string]interface{}, model interface{}, relationshipHelper RelationshipInfoProvider) bool
ShouldUseNestedProcessor determines if we should use nested CUD processing It checks if the data contains nested relations or a _request field
Types ¶
type CRUDRequestProvider ¶ added in v0.0.20
type CRUDRequestProvider interface {
GetRequest() string
}
CRUDRequestProvider interface for models that provide CRUD request strings
type ColumnValidator ¶
type ColumnValidator struct {
// contains filtered or unexported fields
}
ColumnValidator validates column names against a model's fields
func NewColumnValidator ¶
func NewColumnValidator(model interface{}) *ColumnValidator
NewColumnValidator creates a new column validator for a given model
func (*ColumnValidator) FilterRequestOptions ¶
func (v *ColumnValidator) FilterRequestOptions(options RequestOptions) RequestOptions
FilterRequestOptions filters all column references in RequestOptions Returns a new RequestOptions with only valid columns, logging warnings for invalid ones
func (*ColumnValidator) FilterValidColumns ¶
func (v *ColumnValidator) FilterValidColumns(columns []string) []string
FilterValidColumns filters a list of columns, returning only valid ones Logs warnings for any invalid columns
func (*ColumnValidator) GetValidColumns ¶
func (v *ColumnValidator) GetValidColumns() []string
GetValidColumns returns a list of all valid column names for debugging purposes
func (*ColumnValidator) IsValidColumn ¶
func (v *ColumnValidator) IsValidColumn(column string) bool
IsValidColumn checks if a column is valid Returns true if valid, false if invalid
func (*ColumnValidator) ValidateColumn ¶
func (v *ColumnValidator) ValidateColumn(column string) error
ValidateColumn validates a single column name Returns nil if valid, error if invalid Columns prefixed with "cql" (case insensitive) are always valid
func (*ColumnValidator) ValidateColumns ¶
func (v *ColumnValidator) ValidateColumns(columns []string) error
ValidateColumns validates multiple column names Returns error with details about all invalid columns
func (*ColumnValidator) ValidateRequestOptions ¶
func (v *ColumnValidator) ValidateRequestOptions(options RequestOptions) error
ValidateRequestOptions validates all column references in RequestOptions
type ComputedColumn ¶
type CustomOperator ¶
type Database ¶
type Database interface {
// Core query operations
NewSelect() SelectQuery
NewInsert() InsertQuery
NewUpdate() UpdateQuery
NewDelete() DeleteQuery
// Raw SQL execution
Exec(ctx context.Context, query string, args ...interface{}) (Result, error)
Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// Transaction support
BeginTx(ctx context.Context) (Database, error)
CommitTx(ctx context.Context) error
RollbackTx(ctx context.Context) error
RunInTransaction(ctx context.Context, fn func(Database) error) error
}
Database interface designed to work with both GORM and Bun
type DeleteQuery ¶
type DeleteQuery interface {
Model(model interface{}) DeleteQuery
Table(table string) DeleteQuery
Where(query string, args ...interface{}) DeleteQuery
// Execution
Exec(ctx context.Context) (Result, error)
}
DeleteQuery interface for building DELETE queries
type FilterOption ¶
type HTTPHandlerFunc ¶
type HTTPHandlerFunc func(ResponseWriter, Request)
HTTPHandlerFunc type for HTTP handlers
type InsertQuery ¶
type InsertQuery interface {
Model(model interface{}) InsertQuery
Table(table string) InsertQuery
Value(column string, value interface{}) InsertQuery
OnConflict(action string) InsertQuery
Returning(columns ...string) InsertQuery
// Execution
Exec(ctx context.Context) (Result, error)
}
InsertQuery interface for building INSERT queries
type ModelRegistry ¶
type ModelRegistry interface {
RegisterModel(name string, model interface{}) error
GetModel(name string) (interface{}, error)
GetAllModels() map[string]interface{}
GetModelByEntity(schema, entity string) (interface{}, error)
}
ModelRegistry manages model registration and retrieval
type NestedCUDProcessor ¶ added in v0.0.20
type NestedCUDProcessor struct {
// contains filtered or unexported fields
}
NestedCUDProcessor handles recursive processing of nested object graphs
func NewNestedCUDProcessor ¶ added in v0.0.20
func NewNestedCUDProcessor(db Database, registry ModelRegistry, relationshipHelper RelationshipInfoProvider) *NestedCUDProcessor
NewNestedCUDProcessor creates a new nested CUD processor
func (*NestedCUDProcessor) ProcessNestedCUD ¶ added in v0.0.20
func (p *NestedCUDProcessor) ProcessNestedCUD( ctx context.Context, operation string, data map[string]interface{}, model interface{}, parentIDs map[string]interface{}, tableName string, ) (*ProcessResult, error)
ProcessNestedCUD recursively processes nested object graphs for Create, Update, Delete operations with automatic foreign key resolution
type PreloadOption ¶
type PreloadOption struct {
Relation string `json:"relation"`
Columns []string `json:"columns"`
OmitColumns []string `json:"omit_columns"`
Sort []SortOption `json:"sort"`
Filters []FilterOption `json:"filters"`
Where string `json:"where"`
Limit *int `json:"limit"`
Offset *int `json:"offset"`
Updatable *bool `json:"updateable"` // if true, the relation can be updated
}
type PrimaryKeyNameProvider ¶
type PrimaryKeyNameProvider interface {
GetIDName() string
}
PrimaryKeyNameProvider interface for models that provide primary key column names
type ProcessResult ¶ added in v0.0.20
type ProcessResult struct {
ID interface{} // The ID of the processed record
AffectedRows int64 // Number of rows affected
Data map[string]interface{} // The processed data
RelationData map[string]interface{} // Data from processed relations
}
ProcessResult contains the result of processing a CUD operation
type RelationshipInfo ¶ added in v0.0.20
type RelationshipInfo struct {
FieldName string
JSONName string
RelationType string // "belongsTo", "hasMany", "hasOne", "many2many"
ForeignKey string
References string
JoinTable string
RelatedModel interface{}
}
RelationshipInfo contains information about a model relationship
type RelationshipInfoProvider ¶ added in v0.0.20
type RelationshipInfoProvider interface {
GetRelationshipInfo(modelType reflect.Type, relationName string) *RelationshipInfo
}
RelationshipInfoProvider interface for handlers that can provide relationship info
type Request ¶
type Request interface {
Method() string
URL() string
Header(key string) string
AllHeaders() map[string]string // Get all headers as a map
Body() ([]byte, error)
PathParam(key string) string
QueryParam(key string) string
}
Request interface abstracts HTTP request
type RequestBody ¶
type RequestBody struct {
Operation string `json:"operation"`
Data interface{} `json:"data"`
ID *int64 `json:"id"`
Options RequestOptions `json:"options"`
}
type RequestOptions ¶
type RequestOptions struct {
Preload []PreloadOption `json:"preload"`
Columns []string `json:"columns"`
OmitColumns []string `json:"omit_columns"`
Filters []FilterOption `json:"filters"`
Sort []SortOption `json:"sort"`
Limit *int `json:"limit"`
Offset *int `json:"offset"`
CustomOperators []CustomOperator `json:"customOperators"`
ComputedColumns []ComputedColumn `json:"computedColumns"`
Parameters []Parameter `json:"parameters"`
// Cursor pagination
CursorForward string `json:"cursor_forward"`
CursorBackward string `json:"cursor_backward"`
FetchRowNumber *string `json:"fetch_row_number"`
}
type Response ¶
type Response struct {
Success bool `json:"success"`
Data interface{} `json:"data"`
Metadata *Metadata `json:"metadata,omitempty"`
Error *APIError `json:"error,omitempty"`
}
Response structures
type ResponseWriter ¶
type ResponseWriter interface {
SetHeader(key, value string)
WriteHeader(statusCode int)
Write(data []byte) (int, error)
WriteJSON(data interface{}) error
}
ResponseWriter interface abstracts HTTP response
type RouteRegistration ¶
type RouteRegistration interface {
Methods(methods ...string) RouteRegistration
PathPrefix(prefix string) RouteRegistration
}
RouteRegistration allows method chaining for route configuration
type Router ¶
type Router interface {
HandleFunc(pattern string, handler HTTPHandlerFunc) RouteRegistration
ServeHTTP(w ResponseWriter, r Request)
}
Router interface for HTTP router abstraction
type SchemaProvider ¶
type SchemaProvider interface {
SchemaName() string
}
SchemaProvider interface for models that provide schema names
type SelectQuery ¶
type SelectQuery interface {
Model(model interface{}) SelectQuery
Table(table string) SelectQuery
Column(columns ...string) SelectQuery
ColumnExpr(query string, args ...interface{}) SelectQuery
Where(query string, args ...interface{}) SelectQuery
WhereOr(query string, args ...interface{}) SelectQuery
Join(query string, args ...interface{}) SelectQuery
LeftJoin(query string, args ...interface{}) SelectQuery
Preload(relation string, conditions ...interface{}) SelectQuery
PreloadRelation(relation string, apply ...func(SelectQuery) SelectQuery) SelectQuery
Order(order string) SelectQuery
Limit(n int) SelectQuery
Offset(n int) SelectQuery
Group(group string) SelectQuery
Having(having string, args ...interface{}) SelectQuery
// Execution methods
Scan(ctx context.Context, dest interface{}) error
ScanModel(ctx context.Context) error
Count(ctx context.Context) (int, error)
Exists(ctx context.Context) (bool, error)
}
SelectQuery interface for building SELECT queries (compatible with both GORM and Bun)
type SortOption ¶
type TableAliasProvider ¶ added in v0.0.20
type TableAliasProvider interface {
TableAlias() string
}
type TableMetadata ¶
type TableNameProvider ¶
type TableNameProvider interface {
TableName() string
}
TableNameProvider interface for models that provide table names
type UpdateQuery ¶
type UpdateQuery interface {
Model(model interface{}) UpdateQuery
Table(table string) UpdateQuery
Set(column string, value interface{}) UpdateQuery
SetMap(values map[string]interface{}) UpdateQuery
Where(query string, args ...interface{}) UpdateQuery
Returning(columns ...string) UpdateQuery
// Execution
Exec(ctx context.Context) (Result, error)
}
UpdateQuery interface for building UPDATE queries