Skip to content

Encode Values should take into account pointers to structs #23

@Smithx10

Description

@Smithx10

Currently encodeValues() Doesn't check for pointer to struct
Doesn't work:

func encodeValues(v any, skipType string, skipZeroValues bool) map[string]SQLValuer {
	t := reflect.ValueOf(v)
	// if we received a map we will just convert it to a map of SQLValuer
	if t.Kind() == reflect.Map {
		return convertMapToSQLValuer(v.(map[string]any))
	}
	fields := reflect.VisibleFields(t.Type())

works:

	t := reflect.ValueOf(v)
	// if we received a map we will just convert it to a map of SQLValuer
	if t.Kind() == reflect.Map {
		return convertMapToSQLValuer(v.(map[string]any))
	}
        // Check if the type is a pointer
        if t.Kind() == reflect.Pointer {
                t = t.Elem() // Dereference to get the underlying type
        }	
        fields := reflect.VisibleFields(t.Type())

Doesn't work:

func (c *GroupsClient) Create(ctx context.Context, i *CreateGroupInput) (*Group, error) {

	g, err := gx.Insert[Group](ctx, c.p, g_iam_group.GetTable(), i, gx.WithInsertReturningAll())
	if err != nil {
		return nil, err
	}

...

works:

func (c *GroupsClient) Create(ctx context.Context, i *CreateGroupInput) (*Group, error) {

	g, err := gx.Insert[Group](ctx, c.p, g_iam_group.GetTable(), *i, gx.WithInsertReturningAll())
	if err != nil {
		return nil, err
	}

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions