2

i have create remote schema for some purpose i have to insert a json value like this

"convert_to_money": {"IDR":10000},

i create a mutation field like this

"convert_to_money": {
 Type: scalar.JSON,
},

resolver like this :

Convert_to_money := p.Args["convert_to_money"].(map[string]interface{})

struct like this :

type TimeOvertimePolicy struct {
    ConvertToMoney          JSONB
}

and handler like this :

func UpdateOvertimesPolicy(Convert_to_money model.JSONB) (res gqltypes.SuccessType, err error) {
  timeOvertimesPolicy := model.TimeOvertimePolicy{
        ConvertToMoney:         Convert_to_money,
    }

  err = pg.DB.Transaction(func(tx *gorm.DB) error {
    d := tx.Create(&timeOvertimesPolicy)
  }
}

How can i do input null value for case like this?

Which is running now I have to insert a variable "convert_to_money": {} like this if the variable is null

I wish i can insert variable like this if null

"convert_to_money": null

3 Answers 3

1

In go nil (null) exist for pointers. So if you want to insert a nil value then your Convert_to_money should be of a pointer type.

Sign up to request clarification or add additional context in comments.

Comments

0

You can insert vairable like this

"convert_to_money": nil

Comments

0

If you're using gorm, you can use pgtype.JSONB to init a "null" value:

pgtype.JSONB{Status: pgtype.Null}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.