mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-01 09:44:24 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1261960e97 | ||
|
|
76bbf33db2 |
@@ -199,7 +199,9 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
|||||||
// Apply column selection
|
// Apply column selection
|
||||||
if len(options.Columns) > 0 {
|
if len(options.Columns) > 0 {
|
||||||
logger.Debug("Selecting columns: %v", options.Columns)
|
logger.Debug("Selecting columns: %v", options.Columns)
|
||||||
query = query.Column(options.Columns...)
|
for _, col := range options.Columns {
|
||||||
|
query = query.Column(reflection.ExtractSourceColumn(col))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(options.ComputedColumns) > 0 {
|
if len(options.ComputedColumns) > 0 {
|
||||||
|
|||||||
@@ -213,6 +213,10 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
|||||||
tableName := GetTableName(ctx)
|
tableName := GetTableName(ctx)
|
||||||
model := GetModel(ctx)
|
model := GetModel(ctx)
|
||||||
|
|
||||||
|
if id == "" {
|
||||||
|
options.SingleRecordAsObject = false
|
||||||
|
}
|
||||||
|
|
||||||
// Execute BeforeRead hooks
|
// Execute BeforeRead hooks
|
||||||
hookCtx := &HookContext{
|
hookCtx := &HookContext{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
@@ -299,7 +303,10 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
|||||||
// Apply column selection
|
// Apply column selection
|
||||||
if len(options.Columns) > 0 {
|
if len(options.Columns) > 0 {
|
||||||
logger.Debug("Selecting columns: %v", options.Columns)
|
logger.Debug("Selecting columns: %v", options.Columns)
|
||||||
query = query.Column(options.Columns...)
|
for _, col := range options.Columns {
|
||||||
|
query = query.Column(reflection.ExtractSourceColumn(col))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply expand (Just expand to Preload for now)
|
// Apply expand (Just expand to Preload for now)
|
||||||
@@ -652,7 +659,6 @@ func (h *Handler) applyPreloadWithRecursion(query common.SelectQuery, preload co
|
|||||||
sq = sq.Order(fmt.Sprintf("%s %s", sort.Column, sort.Direction))
|
sq = sq.Order(fmt.Sprintf("%s %s", sort.Column, sort.Direction))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Apply WHERE clause
|
// Apply WHERE clause
|
||||||
if len(preload.Where) > 0 {
|
if len(preload.Where) > 0 {
|
||||||
|
|||||||
@@ -162,9 +162,17 @@ func (h *Handler) parseOptionsFromHeaders(r common.Request, model interface{}) E
|
|||||||
case strings.HasPrefix(key, "x-searchcols"):
|
case strings.HasPrefix(key, "x-searchcols"):
|
||||||
options.SearchColumns = h.parseCommaSeparated(decodedValue)
|
options.SearchColumns = h.parseCommaSeparated(decodedValue)
|
||||||
case strings.HasPrefix(key, "x-custom-sql-w"):
|
case strings.HasPrefix(key, "x-custom-sql-w"):
|
||||||
options.CustomSQLWhere = decodedValue
|
if options.CustomSQLWhere != "" {
|
||||||
|
options.CustomSQLWhere = fmt.Sprintf("%s AND (%s)", options.CustomSQLWhere, decodedValue)
|
||||||
|
} else {
|
||||||
|
options.CustomSQLWhere = decodedValue
|
||||||
|
}
|
||||||
case strings.HasPrefix(key, "x-custom-sql-or"):
|
case strings.HasPrefix(key, "x-custom-sql-or"):
|
||||||
options.CustomSQLOr = decodedValue
|
if options.CustomSQLOr != "" {
|
||||||
|
options.CustomSQLOr = fmt.Sprintf("%s OR (%s)", options.CustomSQLOr, decodedValue)
|
||||||
|
} else {
|
||||||
|
options.CustomSQLOr = decodedValue
|
||||||
|
}
|
||||||
|
|
||||||
// Joins & Relations
|
// Joins & Relations
|
||||||
case strings.HasPrefix(key, "x-preload"):
|
case strings.HasPrefix(key, "x-preload"):
|
||||||
@@ -226,6 +234,7 @@ func (h *Handler) parseOptionsFromHeaders(r common.Request, model interface{}) E
|
|||||||
case strings.HasPrefix(key, "x-cql-sel-"):
|
case strings.HasPrefix(key, "x-cql-sel-"):
|
||||||
colName := strings.TrimPrefix(key, "x-cql-sel-")
|
colName := strings.TrimPrefix(key, "x-cql-sel-")
|
||||||
options.ComputedQL[colName] = decodedValue
|
options.ComputedQL[colName] = decodedValue
|
||||||
|
|
||||||
case strings.HasPrefix(key, "x-distinct"):
|
case strings.HasPrefix(key, "x-distinct"):
|
||||||
options.Distinct = strings.EqualFold(decodedValue, "true")
|
options.Distinct = strings.EqualFold(decodedValue, "true")
|
||||||
case strings.HasPrefix(key, "x-skipcount"):
|
case strings.HasPrefix(key, "x-skipcount"):
|
||||||
@@ -267,7 +276,7 @@ func (h *Handler) parseOptionsFromHeaders(r common.Request, model interface{}) E
|
|||||||
h.resolveRelationNamesInOptions(&options, model)
|
h.resolveRelationNamesInOptions(&options, model)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Always sort according to the primary key if no sorting is specified
|
// Always sort according to the primary key if no sorting is specified
|
||||||
if len(options.Sort) == 0 {
|
if len(options.Sort) == 0 {
|
||||||
pkName := reflection.GetPrimaryKeyName(model)
|
pkName := reflection.GetPrimaryKeyName(model)
|
||||||
options.Sort = []common.SortOption{{Column: pkName, Direction: "ASC"}}
|
options.Sort = []common.SortOption{{Column: pkName, Direction: "ASC"}}
|
||||||
|
|||||||
Reference in New Issue
Block a user