mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-23 15:51:24 +00:00
Fix db read by id (#192)
This commit is contained in:
@@ -211,7 +211,12 @@ func (e *Db) Read(ctx context.Context, req *db.ReadRequest, rsp *db.ReadResponse
|
||||
if req.Limit == 0 {
|
||||
req.Limit = 25
|
||||
}
|
||||
|
||||
db = db.Table(tableName)
|
||||
if req.Id != "" {
|
||||
logger.Infof("Query by id: %v", req.Id)
|
||||
db = db.Where("id = ?", req.Id)
|
||||
} else {
|
||||
for _, query := range queries {
|
||||
logger.Infof("Query field: %v, op: %v, type: %v", query.Field, query.Op, query.Value)
|
||||
typ := "text"
|
||||
@@ -239,6 +244,8 @@ func (e *Db) Read(ctx context.Context, req *db.ReadRequest, rsp *db.ReadResponse
|
||||
queryField := correctFieldName(query.Field)
|
||||
db = db.Where(fmt.Sprintf("(%v)::%v %v ?", queryField, typ, op), query.Value)
|
||||
}
|
||||
}
|
||||
|
||||
orderField := "created_at"
|
||||
if req.OrderBy != "" {
|
||||
orderField = req.OrderBy
|
||||
|
||||
Reference in New Issue
Block a user