mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-30 08:14:25 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06b2404c0c | ||
|
|
32007480c6 |
@@ -147,8 +147,11 @@ func (b *BunSelectQuery) Column(columns ...string) common.SelectQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BunSelectQuery) ColumnExpr(query string, args ...interface{}) common.SelectQuery {
|
func (b *BunSelectQuery) ColumnExpr(query string, args ...interface{}) common.SelectQuery {
|
||||||
|
if len(args) > 0 {
|
||||||
b.query = b.query.ColumnExpr(query, args)
|
b.query = b.query.ColumnExpr(query, args)
|
||||||
|
} else {
|
||||||
|
b.query = b.query.ColumnExpr(query)
|
||||||
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,12 @@ func (g *GormSelectQuery) Column(columns ...string) common.SelectQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GormSelectQuery) ColumnExpr(query string, args ...interface{}) common.SelectQuery {
|
func (g *GormSelectQuery) ColumnExpr(query string, args ...interface{}) common.SelectQuery {
|
||||||
|
if len(args) > 0 {
|
||||||
g.db = g.db.Select(query, args...)
|
g.db = g.db.Select(query, args...)
|
||||||
|
} else {
|
||||||
|
g.db = g.db.Select(query)
|
||||||
|
}
|
||||||
|
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -333,7 +333,12 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
|||||||
if len(options.ComputedQL) > 0 {
|
if len(options.ComputedQL) > 0 {
|
||||||
for colName, colExpr := range options.ComputedQL {
|
for colName, colExpr := range options.ComputedQL {
|
||||||
logger.Debug("Applying computed column: %s", colName)
|
logger.Debug("Applying computed column: %s", colName)
|
||||||
query = query.ColumnExpr(fmt.Sprintf("(%s) AS %s", colExpr, colName))
|
if strings.Contains(colName, "cql") {
|
||||||
|
query = query.ColumnExpr(fmt.Sprintf("(%s)::text AS %s", colExpr, colName))
|
||||||
|
} else {
|
||||||
|
query = query.ColumnExpr(fmt.Sprintf("(%s)AS %s", colExpr, colName))
|
||||||
|
}
|
||||||
|
|
||||||
for colIndex := range options.Columns {
|
for colIndex := range options.Columns {
|
||||||
if options.Columns[colIndex] == colName {
|
if options.Columns[colIndex] == colName {
|
||||||
// Remove the computed column from the selected columns to avoid duplication
|
// Remove the computed column from the selected columns to avoid duplication
|
||||||
@@ -347,7 +352,12 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
|||||||
if len(options.ComputedColumns) > 0 {
|
if len(options.ComputedColumns) > 0 {
|
||||||
for _, cu := range options.ComputedColumns {
|
for _, cu := range options.ComputedColumns {
|
||||||
logger.Debug("Applying computed column: %s", cu.Name)
|
logger.Debug("Applying computed column: %s", cu.Name)
|
||||||
|
if strings.Contains(cu.Name, "cql") {
|
||||||
|
query = query.ColumnExpr(fmt.Sprintf("(%s)::text AS %s", cu.Expression, cu.Name))
|
||||||
|
} else {
|
||||||
query = query.ColumnExpr(fmt.Sprintf("(%s) AS %s", cu.Expression, cu.Name))
|
query = query.ColumnExpr(fmt.Sprintf("(%s) AS %s", cu.Expression, cu.Name))
|
||||||
|
}
|
||||||
|
|
||||||
for colIndex := range options.Columns {
|
for colIndex := range options.Columns {
|
||||||
if options.Columns[colIndex] == cu.Name {
|
if options.Columns[colIndex] == cu.Name {
|
||||||
// Remove the computed column from the selected columns to avoid duplication
|
// Remove the computed column from the selected columns to avoid duplication
|
||||||
|
|||||||
Reference in New Issue
Block a user