ConvertValueForField converts value to database acceptable value.
(ctx context.Context, fieldType string, fieldValue any)
| 23 | |
| 24 | // ConvertValueForField converts value to database acceptable value. |
| 25 | func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fieldValue any) (any, error) { |
| 26 | if g.IsNil(fieldValue) { |
| 27 | return d.Core.ConvertValueForField(ctx, fieldType, fieldValue) |
| 28 | } |
| 29 | |
| 30 | var fieldValueKind = reflect.TypeOf(fieldValue).Kind() |
| 31 | |
| 32 | if fieldValueKind == reflect.Slice { |
| 33 | // For bytea type, pass []byte directly without any conversion. |
| 34 | if _, ok := fieldValue.([]byte); ok && gstr.Contains(fieldType, "bytea") { |
| 35 | return d.Core.ConvertValueForField(ctx, fieldType, fieldValue) |
| 36 | } |
| 37 | // For pgsql, json or jsonb require '[]' |
| 38 | if !gstr.Contains(fieldType, "json") { |
| 39 | fieldValue = gstr.ReplaceByMap(gconv.String(fieldValue), |
| 40 | map[string]string{ |
| 41 | "[": "{", |
| 42 | "]": "}", |
| 43 | }, |
| 44 | ) |
| 45 | } |
| 46 | } |
| 47 | return d.Core.ConvertValueForField(ctx, fieldType, fieldValue) |
| 48 | } |
| 49 | |
| 50 | // CheckLocalTypeForField checks and returns corresponding local golang type for given db type. |
| 51 | // The parameter `fieldType` is in lower case, like: |
nothing calls this directly
no test coverage detected