Skip to content

Commit

Permalink
Merge pull request #26 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Matrix-X authored Jul 19, 2022
2 parents 5721bed + 1767da7 commit 8b2f0a9
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 152 deletions.
37 changes: 30 additions & 7 deletions database/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package database

import (
"database/sql"
"fmt"
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/google/uuid"
"gorm.io/gorm"
Expand All @@ -19,7 +18,8 @@ type ModelInterface interface {
GetID() int32
GetUUID() string
GetPrimaryKey() string
GetForeignKey() string
GetForeignRefer() string
GetForeignReferValue() string
}

type PowerModel struct {
Expand Down Expand Up @@ -89,8 +89,12 @@ func (mdl *PowerModel) GetUUID() string {
func (mdl *PowerModel) GetPrimaryKey() string {
return "uuid"
}
func (mdl *PowerModel) GetForeignKey() string {
return "model_uuid"

func (mdl *PowerModel) GetForeignRefer() string {
return "uuid"
}
func (mdl *PowerModel) GetForeignReferValue() string {
return mdl.UUID
}

/**
Expand Down Expand Up @@ -215,7 +219,7 @@ func GetModelFields(model interface{}) (fields []string) {
return (*ArrayModelFields)[modelName].([]string)
}

fmt.Printf("parse object ~%s~ model fields \n", modelName)
//fmt.Printf("parse object ~%s~ model fields \n", modelName)
gormSchema, err := schema.Parse(model, &sync.Map{}, schema.NamingStrategy{})
if err != nil {
println(err)
Expand All @@ -229,11 +233,30 @@ func GetModelFields(model interface{}) (fields []string) {
}
}
(*ArrayModelFields)[modelName] = fields
fmt.Printf("parsed object ~%s~ model fields and fields count is %d \n\n", modelName, len(fields))
//fmt.Printf("parsed object ~%s~ model fields and fields count is %d \n\n", modelName, len(fields))

return fields
}

func GetModelFieldValues(model interface{}) (mapFields *object.HashMap, err error) {

//fmt.Printf("parse object ~%s~ model fields \n", modelName)
gormSchema, err := schema.Parse(model, &sync.Map{}, schema.NamingStrategy{})
if err != nil {
println(err)
return mapFields, err
}

mapFields = &object.HashMap{}
for _, field := range gormSchema.Fields {
if field.DBName != "" && !field.PrimaryKey && !field.Unique && field.Updatable {
(*mapFields)[field.DBName] = field.ValueOf
}
}

return mapFields, err
}

func IsPowerModelLoaded(mdl ModelInterface) bool {
if object.IsObjectNil(mdl) {
return false
Expand All @@ -251,7 +274,7 @@ func IsPowerModelLoaded(mdl ModelInterface) bool {
return true
}

func IsPowerRelationshipLoaded(mdl ModelInterface) bool {
func IsPowerPivotLoaded(mdl ModelInterface) bool {

if object.IsObjectNil(mdl) {
return false
Expand Down
Loading

0 comments on commit 8b2f0a9

Please sign in to comment.