Skip to content

Commit 4b12e6f

Browse files
committed
Refactor code
1 parent 1e08373 commit 4b12e6f

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

loader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"strings"
99
)
1010

11-
func InitFields(modelType reflect.Type, table string) (map[string]int, string, error) {
11+
func InitFields(modelType reflect.Type) (map[string]int, string, error) {
1212
fieldsIndex, err := GetColumnIndexes(modelType)
1313
if err != nil {
1414
return nil, "", err
1515
}
16-
query := BuildQuery(table, modelType)
17-
return fieldsIndex, query, nil
16+
fields := BuildFields(modelType)
17+
return fieldsIndex, fields, nil
1818
}
1919
type Loader struct {
2020
DB *gocql.ClusterConfig

util.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ type Schema struct {
4040
Fields map[string]*FieldDB
4141
}
4242

43+
func BuildFieldsBySchema(schema *Schema) string {
44+
columns := make([]string, 0)
45+
for _, s := range schema.SColumns {
46+
columns = append(columns, s)
47+
}
48+
return strings.Join(columns, ",")
49+
}
4350
func BuildQueryBySchema(table string, schema *Schema) string {
4451
columns := make([]string, 0)
4552
for _, s := range schema.SColumns {
@@ -49,7 +56,7 @@ func BuildQueryBySchema(table string, schema *Schema) string {
4956
}
5057
func BuildFields(modelType reflect.Type) string {
5158
columns := GetFields(modelType)
52-
return " " + strings.Join(columns, ",") + " "
59+
return strings.Join(columns, ",")
5360
}
5461
func GetFields(modelType reflect.Type) []string {
5562
m := modelType

writer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
"strings"
1010
)
1111

12-
func Init(modelType reflect.Type, table string) (map[string]int, *Schema, map[string]string, []string, []string, string, error) {
12+
func Init(modelType reflect.Type) (map[string]int, *Schema, map[string]string, []string, []string, string, error) {
1313
fieldsIndex, err := GetColumnIndexes(modelType)
1414
if err != nil {
1515
return nil, nil, nil, nil, nil, "", err
1616
}
1717
schema := CreateSchema(modelType)
18-
query := BuildQueryBySchema(table, schema)
18+
fields := BuildFieldsBySchema(schema)
1919
jsonColumnMap := MakeJsonColumnMap(modelType)
2020
keys, arr := FindPrimaryKeys(modelType)
21-
return fieldsIndex, schema, jsonColumnMap, keys, arr, query, nil
21+
return fieldsIndex, schema, jsonColumnMap, keys, arr, fields, nil
2222
}
2323

2424
type Writer struct {

0 commit comments

Comments
 (0)