diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6324ccb..d820f16 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -3,7 +3,7 @@ name: Build and test on: push: branches: - - main + - '*' pull_request: branches: - main @@ -25,8 +25,6 @@ jobs: - name: Run linters uses: golangci/golangci-lint-action@v2 - with: - args: -D unused -D staticcheck -D gosimple build: runs-on: ubuntu-latest @@ -61,6 +59,7 @@ jobs: #Trying https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers test-postgresql: + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest services: @@ -104,6 +103,7 @@ jobs: GCA_CONFIG_FILE: ${{ github.workspace }}/test/yaml/gcaconfig_pgsql.yaml test-mysql: + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest services: @@ -148,6 +148,7 @@ jobs: GCA_API_PORT: ${{ job.services.mysqldb.ports['3306'] }} test-sqlserver: + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest services: diff --git a/README.md b/README.md index 996dde0..c71fef4 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ Those go packages are used : - [ ] Add a github workflow - [X] Init - [X] Add pgsql, mysql and sqlserver testing - - [ ] Find why somes linters are not working : linked to https://github.com/golang/go/issues/26863, should rewrite condition interface. See also https://github.com/golang/go/issues/28254#issuecomment-996822778 + - [X] Find why somes linters are not working : linked to https://github.com/golang/go/issues/26863, should rewrite condition interface. See also https://github.com/golang/go/issues/28254#issuecomment-996822778 - [X] Release pipeline - [ ] Add an alter table function for sqlite (create new table, copy data, drop old table) - [X] Review packages structure diff --git a/pkg/controller/geojsoncontroller.go b/pkg/controller/geojsoncontroller.go index f5b7203..5a8995b 100644 --- a/pkg/controller/geojsoncontroller.go +++ b/pkg/controller/geojsoncontroller.go @@ -34,7 +34,6 @@ func (gc *GeoJsonController) list(w http.ResponseWriter, r *http.Request) { } else { gc.responder.Success(result, w) } - return } func (gc *GeoJsonController) read(w http.ResponseWriter, r *http.Request) { @@ -49,7 +48,7 @@ func (gc *GeoJsonController) read(w http.ResponseWriter, r *http.Request) { } params := utils.GetRequestParams(r) id := mux.Vars(r)["id"] - if strings.Index(id, ",") != -1 { + if strings.Contains(id, ",") { ids := strings.Split(id, `,`) results := struct { Type string `json:"type"` diff --git a/pkg/controller/recordcontroller.go b/pkg/controller/recordcontroller.go index ffc4a5c..9c34439 100644 --- a/pkg/controller/recordcontroller.go +++ b/pkg/controller/recordcontroller.go @@ -38,7 +38,6 @@ func (rc *RecordController) list(w http.ResponseWriter, r *http.Request) { } result := rc.service.List(table, params) rc.responder.Success(result, w) - return } type argumentList struct { @@ -56,7 +55,7 @@ func (rc *RecordController) read(w http.ResponseWriter, r *http.Request) { } params := utils.GetRequestParams(r) id := mux.Vars(r)["id"] - if strings.Index(id, ",") != -1 { + if strings.Contains(id, ",") { ids := strings.Split(id, `,`) var argumentLists []*argumentList for i := 0; i < len(ids); i++ { @@ -195,7 +194,7 @@ func (rc *RecordController) delete(w http.ResponseWriter, r *http.Request) { } params := utils.GetRequestParams(r) id := mux.Vars(r)["id"] - if strings.Index(id, ",") != -1 { + if strings.Contains(id, ",") { ids := strings.Split(id, `,`) var argumentLists []*argumentList for i := 0; i < len(ids); i++ { diff --git a/pkg/database/condition.go b/pkg/database/condition.go index ce2839b..6473300 100644 --- a/pkg/database/condition.go +++ b/pkg/database/condition.go @@ -6,39 +6,41 @@ import ( // Condition interface type Condition interface { - GetCondition() interface{ Condition } - And(condition interface{ Condition }) interface{ Condition } - Or(condition interface{ Condition }) interface{ Condition } - Not() interface{ Condition } + GetCondition() interface{} + And(condition interface{}) interface{} + Or(condition interface{}) interface{} + Not() interface{} } type GenericCondition struct { condition interface{ Condition } } -func (gc *GenericCondition) And(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (gc *GenericCondition) And(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return gc.condition - default: - return NewAndCondition(gc.condition, condition) + case interface{ Condition }: + return NewAndCondition(gc.condition, c) } + return nil } -func (gc *GenericCondition) Or(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (gc *GenericCondition) Or(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return gc.condition - default: - return NewOrCondition(gc.condition, condition) + case interface{ Condition }: + return NewOrCondition(gc.condition, c) } + return nil } -func (gc *GenericCondition) Not() interface{ Condition } { +func (gc *GenericCondition) Not() interface{} { return NewNotCondition(gc.condition) } -func (gc *GenericCondition) GetCondition() interface{ Condition } { +func (gc *GenericCondition) GetCondition() interface{} { return nil } @@ -76,7 +78,7 @@ func ConditionFromString(table *ReflectedTable, value string) interface{ Conditi condition = NewColumnCondition(field, command, parts[2]) } if negate { - condition = condition.Not() + condition = condition.Not().(interface{ Condition }) } return condition } @@ -92,19 +94,19 @@ func NewNoCondition() *NoCondition { } -func (nc *NoCondition) GetCondition() interface{ Condition } { +func (nc *NoCondition) GetCondition() interface{} { return nil } -func (nc *NoCondition) And(condition interface{ Condition }) interface{ Condition } { +func (nc *NoCondition) And(condition interface{}) interface{} { return condition } -func (nc *NoCondition) Or(condition interface{ Condition }) interface{ Condition } { +func (nc *NoCondition) Or(condition interface{}) interface{} { return condition } -func (nc *NoCondition) Not() interface{ Condition } { +func (nc *NoCondition) Not() interface{} { return nc } @@ -120,25 +122,27 @@ func NewNotCondition(condition interface{ Condition }) *NotCondition { return &NotCondition{condition, GenericCondition{condition}} } -func (nc *NotCondition) And(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (nc *NotCondition) And(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return nc - default: - return NewAndCondition(nc, condition) + case interface{ Condition }: + return NewAndCondition(nc, c) } + return nil } -func (nc *NotCondition) Or(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (nc *NotCondition) Or(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return nc - default: - return NewOrCondition(nc, condition) + case interface{ Condition }: + return NewOrCondition(nc, c) } + return nil } -func (nc *NotCondition) GetCondition() interface{ Condition } { +func (nc *NotCondition) GetCondition() interface{} { return nc.condition } @@ -154,23 +158,25 @@ func NewOrCondition(condition1, condition2 interface{ Condition }) *OrCondition return &OrCondition{[]interface{ Condition }{condition1, condition2}, GenericCondition{}} } -func (oc *OrCondition) Or(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (oc *OrCondition) Or(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return oc - default: - oc.conditions = append(oc.conditions, condition) + case interface{ Condition }: + oc.conditions = append(oc.conditions, c) return oc } + return nil } -func (oc *OrCondition) And(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (oc *OrCondition) And(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return oc - default: - return NewAndCondition(oc, condition) + case interface{ Condition }: + return NewAndCondition(oc, c) } + return nil } func (ac *OrCondition) GetConditions() []interface{ Condition } { @@ -181,7 +187,9 @@ func OrConditionFromArray(conditions []interface{ Condition }) interface{ Condit var condition interface{ Condition } condition = NewNoCondition() for _, c := range conditions { - condition = condition.Or(c) + if ct, ok := condition.Or(c).(interface{ Condition }); ok { + condition = ct + } } return condition } @@ -198,23 +206,25 @@ func NewAndCondition(condition1, condition2 interface{ Condition }) *AndConditio return &AndCondition{[]interface{ Condition }{condition1, condition2}, GenericCondition{}} } -func (ac *AndCondition) And(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (ac *AndCondition) And(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return ac - default: - ac.conditions = append(ac.conditions, condition) + case interface{ Condition }: + ac.conditions = append(ac.conditions, c) return ac } + return nil } -func (ac *AndCondition) Or(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (ac *AndCondition) Or(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return ac - default: - return NewOrCondition(ac, condition) + case interface{ Condition }: + return NewOrCondition(ac, c) } + return nil } func (ac *AndCondition) GetConditions() []interface{ Condition } { @@ -225,7 +235,9 @@ func AndConditionFromArray(conditions []interface{ Condition }) interface{ Condi var condition interface{ Condition } condition = NewNoCondition() for _, c := range conditions { - condition = condition.And(c) + if ct, ok := condition.And(c).(interface{ Condition }); ok { + condition = ct + } } return condition } @@ -273,20 +285,22 @@ func NewSpatialCondition(column *ReflectedColumn, operator, value string) *Spati return &SpatialCondition{*condition} } -func (sc *SpatialCondition) And(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (sc *SpatialCondition) And(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return sc - default: - return NewAndCondition(sc, condition) + case interface{ Condition }: + return NewAndCondition(sc, c) } + return nil } -func (sc *SpatialCondition) Or(condition interface{ Condition }) interface{ Condition } { - switch condition.(type) { +func (sc *SpatialCondition) Or(condition interface{}) interface{} { + switch c := condition.(type) { case *NoCondition: return sc - default: - return NewOrCondition(sc, condition) + case interface{ Condition }: + return NewOrCondition(sc, c) } + return nil } diff --git a/pkg/database/conditionsbuilder.go b/pkg/database/conditionsbuilder.go index bdfc713..c9fc5a0 100644 --- a/pkg/database/conditionsbuilder.go +++ b/pkg/database/conditionsbuilder.go @@ -49,7 +49,7 @@ func (cb *ConditionsBuilder) getOrConditionSql(or *OrCondition, arguments *[]int } func (cb *ConditionsBuilder) getNotConditionSql(not *NotCondition, arguments *[]interface{}) string { - condition := not.GetCondition() + condition := not.GetCondition().(interface{ Condition }) return "(NOT " + cb.getConditionSql(condition, arguments) + ")" } @@ -70,9 +70,8 @@ func (cb *ConditionsBuilder) escapeLikeValue(value string) string { // Addcslashes - Quote string with slashes in a C style func (cb *ConditionsBuilder) addcslashes(s string, c string) string { var tmpRune []rune - strRune := []rune(s) list := []rune(c) - for _, ch := range strRune { + for _, ch := range s { for _, v := range list { if ch == v { tmpRune = append(tmpRune, '\\') diff --git a/pkg/database/genericdb.go b/pkg/database/genericdb.go index 3d53d04..8fb3430 100644 --- a/pkg/database/genericdb.go +++ b/pkg/database/genericdb.go @@ -179,11 +179,11 @@ func (g *GenericDB) RollBackTransaction(tx *sql.Tx) error { func (g *GenericDB) addMiddlewareConditions(tableName string, condition interface{ Condition }) interface{ Condition } { condition1 := g.VariableStore.Get("authorization.conditions." + tableName) if condition1 != nil { - condition = condition.And(condition1.(interface{ Condition })) + condition = condition.And(condition1).(interface{ Condition }) } condition2 := g.VariableStore.Get("multiTenancy.conditions." + tableName) if condition2 != nil { - condition = condition.And(condition2.(interface{ Condition })) + condition = condition.And(condition2).(interface{ Condition }) } return condition } diff --git a/pkg/database/realnamemapper.go b/pkg/database/realnamemapper.go index 3ee8423..fdacd12 100644 --- a/pkg/database/realnamemapper.go +++ b/pkg/database/realnamemapper.go @@ -15,7 +15,7 @@ func NewRealNameMapper(mapping map[string]string) *RealNameMapper { columnMapping := map[string]map[string]string{} reverseColumnMapping := map[string]map[string]string{} for name, realName := range mapping { - if strings.Index(name, ".") >= 0 && strings.Index(realName, ".") >= 0 { + if strings.Contains(name, ".") && strings.Contains(realName, ".") { nameSplit := strings.SplitN(name, ".", 2) realNameSplit := strings.SplitN(realName, ".", 2) tableMapping[nameSplit[0]] = realNameSplit[0] diff --git a/pkg/database/reflectedtable.go b/pkg/database/reflectedtable.go index 6e599ce..cad9d97 100644 --- a/pkg/database/reflectedtable.go +++ b/pkg/database/reflectedtable.go @@ -69,8 +69,8 @@ func NewReflectedTableFromReflection(reflection *GenericReflection, name, realNa tableName := table["TABLE_NAME"].(string) suffix := tableName + "_id" if columnName[len(columnName)-len(suffix):] == suffix { + column.SetFk(tableName) } - column.SetFk(tableName) } } } diff --git a/pkg/middleware/jwtauth.go b/pkg/middleware/jwtauth.go index ec76c24..568b692 100644 --- a/pkg/middleware/jwtauth.go +++ b/pkg/middleware/jwtauth.go @@ -147,7 +147,7 @@ func (ja *JwtAuthMiddleware) getVerifiedClaims(token string, time int64, leeway, } for field, values := range requirements { - if values != nil && len(values) > 0 { + if len(values) > 0 { if field == "alg" { cfield, exists := claims[field] if !exists { diff --git a/pkg/middleware/multitenancymiddleware.go b/pkg/middleware/multitenancymiddleware.go index 2bd1156..3ecb349 100644 --- a/pkg/middleware/multitenancymiddleware.go +++ b/pkg/middleware/multitenancymiddleware.go @@ -31,7 +31,7 @@ func (mt *MultiTenancy) getCondition(tableName string, pairs map[string]string) condition = database.NewNoCondition() table := mt.reflection.GetTable(tableName) for k, v := range pairs { - condition = condition.And(database.NewColumnCondition(table.GetColumn(k), "eq", v)) + condition = condition.And(database.NewColumnCondition(table.GetColumn(k), "eq", v)).(interface{ database.Condition }) } return condition } @@ -86,7 +86,7 @@ func (mt *MultiTenancy) handleRecord(r *http.Request, operation string, pairs ma for column, value := range pairs { if operation == "create" { records[i][column] = value - } else if _, exists := records[i][column]; exists { + } else { delete(records[i], column) } } diff --git a/pkg/middleware/pagelimits.go b/pkg/middleware/pagelimits.go index b4d9328..68186a0 100644 --- a/pkg/middleware/pagelimits.go +++ b/pkg/middleware/pagelimits.go @@ -30,7 +30,7 @@ func (pm *PageLimitsMiddleware) Process(next http.Handler) http.Handler { if v, ok := params["page"]; ok && len(v) > 0 && maxPage > 0 { var page int var err error - if strings.Index(v[0], ",") == -1 { + if !strings.Contains(v[0], ",") { page, err = strconv.Atoi(v[0]) } else { page, err = strconv.Atoi(strings.SplitN(v[0], ",", 2)[0]) diff --git a/pkg/middleware/reconnectmiddleware.go b/pkg/middleware/reconnectmiddleware.go index 53448c0..7a8058d 100644 --- a/pkg/middleware/reconnectmiddleware.go +++ b/pkg/middleware/reconnectmiddleware.go @@ -69,7 +69,7 @@ func (rm *ReconnectMiddleware) Process(next http.Handler) http.Handler { port := rm.getIntFromHandler("portHandler") database := rm.getStringFromHandler("databaseHandler") //We expect tables in a csv string and convert to map[string]bool - var tables map[string]bool + tables := map[string]bool{} if tablesStr := rm.getStringFromHandler("tablesHandler"); tablesStr != "" { for _, table := range strings.Split(tablesStr, ",") { tables[table] = true diff --git a/pkg/middleware/validationmiddleware.go b/pkg/middleware/validationmiddleware.go index b4e7e5e..869c8c6 100644 --- a/pkg/middleware/validationmiddleware.go +++ b/pkg/middleware/validationmiddleware.go @@ -19,8 +19,6 @@ import ( "github.com/dranih/go-crud-api/pkg/database" "github.com/dranih/go-crud-api/pkg/record" "github.com/dranih/go-crud-api/pkg/utils" - - "github.com/carmo-evan/strtotime" ) type ValidationMiddleware struct { @@ -122,7 +120,7 @@ func (vm *ValidationMiddleware) validateType(table *database.ReflectedTable, col } case "decimal": var whole, decimals string - if strings.Index(v, ".") != -1 { + if strings.Contains(v, ".") { a := strings.SplitN(strings.TrimLeft(v, "-"), ".", 2) whole = a[0] decimals = a[1] @@ -173,7 +171,6 @@ func (vm *ValidationMiddleware) validateType(table *database.ReflectedTable, col if column.HasLength() && utf8.RuneCountInString(v) > column.GetLength() { return "string too long", false } - break case "blob", "varbinary": padVal := strings.ReplaceAll(v, `-`, `+`) padVal = strings.ReplaceAll(padVal, `_`, `/`) @@ -184,10 +181,8 @@ func (vm *ValidationMiddleware) validateType(table *database.ReflectedTable, col } else if column.HasLength() && len(val) > column.GetLength() { return "string too long", false } - break case "geometry": // no checks yet - break } } else { // check non-string types switch column.GetType() { @@ -239,64 +234,6 @@ func (vm *ValidationMiddleware) validateType(table *database.ReflectedTable, col return "", true } -func (vm *ValidationMiddleware) sanitizeType(table *database.ReflectedTable, column *database.ReflectedColumn, value string) interface{} { - var newValue interface{} - tables := vm.getArrayProperty("tables", "all") - types := vm.getArrayProperty("types", "all") - if (tables["all"] || tables[table.GetName()]) && (types["all"] || types[column.GetType()]) { - if value == "" { - return value - } - newValue = value - switch column.GetType() { - case "integer", "bigint": - if v, err := strconv.ParseFloat(value, 0); err == nil { - newValue = v - } - case "decimal": - if v, err := strconv.ParseFloat(value, 64); err == nil { - newValue = strconv.FormatFloat(v, 'g', column.GetScale(), 64) - } - case "float": - if v, err := strconv.ParseFloat(value, 32); err == nil { - newValue = v - } - case "double": - if v, err := strconv.ParseFloat(value, 64); err == nil { - newValue = v - } - case "boolean": - if v, err := strconv.ParseBool(value); err == nil { - newValue = v - } - case "date": - if v, err := strtotime.Parse(value, time.Now().Unix()); err == nil { - t := time.Unix(v, 0).Local().UTC() - newValue = fmt.Sprintf("%d-%02d-%02d", t.Year(), int(t.Month()), t.Day()) - } - case "time": - if v, err := strtotime.Parse(value, time.Now().Unix()); err == nil { - t := time.Unix(v, 0).Local().UTC() - newValue = fmt.Sprintf("%02d:%02d:%02d", t.Hour(), int(t.Minute()), t.Second()) - } - case "timestamp": - if v, err := strtotime.Parse(value, time.Now().Unix()); err == nil { - t := time.Unix(v, 0).Local().UTC() - newValue = fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d", t.Year(), int(t.Month()), t.Day(), t.Hour(), int(t.Minute()), t.Second()) - } - case "blob", "varbinary": - // allow base64url format - v := strings.ReplaceAll(strings.TrimSpace(value), `-`, `+`) - newValue = strings.ReplaceAll(v, `_`, `/`) - case "clob", "varchar": - newValue = value - case "geometry": - newValue = strings.TrimSpace(value) - } - } - return newValue -} - func (vm *ValidationMiddleware) Process(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { operation := utils.GetOperation(r) diff --git a/pkg/openapi/openapicolumnsbuilder.go b/pkg/openapi/openapicolumnsbuilder.go index 91f0367..4a3cb27 100644 --- a/pkg/openapi/openapicolumnsbuilder.go +++ b/pkg/openapi/openapicolumnsbuilder.go @@ -69,10 +69,10 @@ func (oacb *OpenApiColumnsBuilder) setPaths() { path = "/columns/{table}/{column}" } } - if strings.Index(path, "{table}") >= 0 { + if strings.Contains(path, "{table}") { parameters = append(parameters, "table") } - if strings.Index(path, "{column}") >= 0 { + if strings.Contains(path, "{column}") { parameters = append(parameters, "column") } for p, parameter := range parameters { @@ -135,7 +135,6 @@ func (oacb *OpenApiColumnsBuilder) setComponentSchema() { oacb.openapi.Set(fmt.Sprintf("%s|properties|nullable|type", prefix), "boolean") oacb.openapi.Set(fmt.Sprintf("%s|properties|pk|type", prefix), "boolean") oacb.openapi.Set(fmt.Sprintf("%s|properties|fk|type", prefix), "string") - break } } } diff --git a/pkg/openapi/openapirecordsbuilder.go b/pkg/openapi/openapirecordsbuilder.go index 627fe01..e4c0f00 100644 --- a/pkg/openapi/openapirecordsbuilder.go +++ b/pkg/openapi/openapirecordsbuilder.go @@ -181,14 +181,14 @@ func (oarb *OpenApiRecordsBuilder) setPath(tableName string) { oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), fmt.Sprintf("/components/responses/%s-%s", operation, normalizedTableName)) case "create": if pk.GetType() == "integer" { - oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), fmt.Sprintf("/components/responses/pk_integer")) + oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), "/components/responses/pk_integer") } else { - oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), fmt.Sprintf("/components/responses/pk_string")) + oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), "/components/responses/pk_string") } case "read": oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), fmt.Sprintf("/components/responses/%s-%s", operation, normalizedTableName)) case "update", "delete", "increment": - oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), fmt.Sprintf("/components/responses/rows_affected")) + oarb.openapi.Set(fmt.Sprintf(`paths|%s|%s|responses|200|$ref`, path, method), "/components/responses/rows_affected") } } } diff --git a/pkg/record/filterinfo.go b/pkg/record/filterinfo.go index c55326d..bdfbb5f 100644 --- a/pkg/record/filterinfo.go +++ b/pkg/record/filterinfo.go @@ -46,7 +46,7 @@ func (ft *FilterInfo) combinePathTreeOfConditions(tree *PathTree) interface{ dat } or := database.OrConditionFromArray(orConditions) cond := and.And(or) - return cond + return cond.(interface{ database.Condition }) } func (ft *FilterInfo) GetCombinedConditions(table *database.ReflectedTable, params map[string][]string) interface{ database.Condition } { diff --git a/pkg/record/recordservice.go b/pkg/record/recordservice.go index 26dae17..70a22f3 100644 --- a/pkg/record/recordservice.go +++ b/pkg/record/recordservice.go @@ -80,7 +80,7 @@ func (rs *RecordService) Read(tx *sql.Tx, tableName string, params map[string][] rs.joiner.AddMandatoryColumns(table, ¶ms) columnNames := rs.columns.GetNames(table, true, params) records := rs.db.SelectSingle(tx, table, columnNames, fmt.Sprint(id[0])) - if records == nil || len(records) < 0 { + if len(records) == 0 { return nil, nil } rs.joiner.AddJoins(table, &records, params, rs.db) @@ -89,7 +89,7 @@ func (rs *RecordService) Read(tx *sql.Tx, tableName string, params map[string][] func (rs *RecordService) Update(tx *sql.Tx, tableName string, params map[string][]string, args ...interface{}) (interface{}, error) { if len(args) < 2 { - return 0, fmt.Errorf("Not enought arguments : %v", args) + return 0, fmt.Errorf("not enought arguments : %v", args) } id := fmt.Sprint(args[0]) record := args[1] @@ -106,7 +106,7 @@ func (rs *RecordService) Delete(tx *sql.Tx, tableName string, params map[string] func (rs *RecordService) Increment(tx *sql.Tx, tableName string, params map[string][]string, args ...interface{}) (interface{}, error) { if len(args) < 2 { - return 0, fmt.Errorf("Not enought arguments : %v", args) + return 0, fmt.Errorf("not enought arguments : %v", args) } id := fmt.Sprint(args[0]) record := args[1] diff --git a/pkg/record/relationjoiner.go b/pkg/record/relationjoiner.go index 7e53868..d8fb096 100644 --- a/pkg/record/relationjoiner.go +++ b/pkg/record/relationjoiner.go @@ -158,9 +158,7 @@ func (rj *RelationJoiner) addFkRecords(t2 *database.ReflectedTable, fkValues map for key := range fkValues { fkIds = append(fkIds, key) } - for _, record := range db.SelectMultiple(t2, columnNames, fkIds) { - *records = append(*records, record) - } + *records = append(*records, db.SelectMultiple(t2, columnNames, fkIds)...) } func (rj *RelationJoiner) fillFkValues(t2 *database.ReflectedTable, fkRecords []map[string]interface{}, fkValues *map[string]map[string]interface{}) { @@ -218,9 +216,7 @@ func (rj *RelationJoiner) addPkRecords(t1, t2 *database.ReflectedTable, pkValues limitInt = -1 } } - for _, record := range db.SelectAll(t2, columnNames, condition, columnOrdering, 0, limitInt) { - *records = append(*records, record) - } + *records = append(*records, db.SelectAll(t2, columnNames, condition, columnOrdering, 0, limitInt)...) } func (rj *RelationJoiner) fillPkValues(t1, t2 *database.ReflectedTable, pkRecords []map[string]interface{}, pkValues *map[string][]map[string]interface{}) {