Compare commits

...

2 Commits

3 changed files with 27 additions and 29 deletions

View File

@@ -165,13 +165,10 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
return
}
// Create a pointer to the model type for database operations
modelPtr := reflect.New(modelType).Interface()
logger.Info("Reading records from %s.%s", schema, entity)
query := h.db.NewSelect().Model(modelPtr)
query = query.Table(tableName)
// Use Table() with the resolved table name (don't use Model() as it would add the table twice)
query := h.db.NewSelect().Table(tableName)
// Apply column selection
if len(options.Columns) > 0 {

View File

@@ -197,8 +197,8 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
logger.Info("Reading records from %s.%s", schema, entity)
query := h.db.NewSelect().Model(modelPtr)
query = query.Table(tableName)
// Use Table() with the resolved table name (don't use Model() as it would add the table twice)
query := h.db.NewSelect().Table(tableName)
// Apply column selection
if len(options.Columns) > 0 {
@@ -695,7 +695,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
if options.CleanJSON {
data = h.cleanJSON(data)
}
w.SetHeader("Content-Type", "application/json")
// Format response based on response format option
switch options.ResponseFormat {
case "simple":

View File

@@ -19,21 +19,21 @@ type ExtendedRequestOptions struct {
CleanJSON bool
// Advanced filtering
SearchColumns []string
SearchColumns []string
CustomSQLWhere string
CustomSQLOr string
CustomSQLOr string
// Joins
Expand []ExpandOption
// Advanced features
AdvancedSQL map[string]string // Column -> SQL expression
ComputedQL map[string]string // Column -> CQL expression
Distinct bool
SkipCount bool
SkipCache bool
AdvancedSQL map[string]string // Column -> SQL expression
ComputedQL map[string]string // Column -> CQL expression
Distinct bool
SkipCount bool
SkipCache bool
FetchRowNumber *string
PKRow *string
PKRow *string
// Response format
ResponseFormat string // "simple", "detail", "syncfusion"
@@ -42,16 +42,16 @@ type ExtendedRequestOptions struct {
AtomicTransaction bool
// Cursor pagination
CursorForward string
CursorForward string
CursorBackward string
}
// ExpandOption represents a relation expansion configuration
type ExpandOption struct {
Relation string
Columns []string
Where string
Sort string
Columns []string
Where string
Sort string
}
// decodeHeaderValue decodes base64 encoded header values
@@ -85,12 +85,13 @@ func (h *Handler) parseOptionsFromHeaders(r common.Request) ExtendedRequestOptio
options := ExtendedRequestOptions{
RequestOptions: common.RequestOptions{
Filters: make([]common.FilterOption, 0),
Sort: make([]common.SortOption, 0),
Sort: make([]common.SortOption, 0),
Preload: make([]common.PreloadOption, 0),
},
AdvancedSQL: make(map[string]string),
ComputedQL: make(map[string]string),
Expand: make([]ExpandOption, 0),
AdvancedSQL: make(map[string]string),
ComputedQL: make(map[string]string),
Expand: make([]ExpandOption, 0),
ResponseFormat: "simple", // Default response format
}
// Get all headers
@@ -212,9 +213,9 @@ func (h *Handler) parseNotSelectFields(options *ExtendedRequestOptions, value st
func (h *Handler) parseFieldFilter(options *ExtendedRequestOptions, headerKey, value string) {
colName := strings.TrimPrefix(headerKey, "x-fieldfilter-")
options.Filters = append(options.Filters, common.FilterOption{
Column: colName,
Column: colName,
Operator: "eq",
Value: value,
Value: value,
})
}
@@ -223,9 +224,9 @@ func (h *Handler) parseSearchFilter(options *ExtendedRequestOptions, headerKey,
colName := strings.TrimPrefix(headerKey, "x-searchfilter-")
// Use ILIKE for fuzzy search
options.Filters = append(options.Filters, common.FilterOption{
Column: colName,
Column: colName,
Operator: "ilike",
Value: "%" + value + "%",
Value: "%" + value + "%",
})
}
@@ -407,7 +408,7 @@ func (h *Handler) parseSorting(options *ExtendedRequestOptions, value string) {
}
options.Sort = append(options.Sort, common.SortOption{
Column: colName,
Column: colName,
Direction: direction,
})
}