Some ideas on improving the Scan method of orm
- 目前从Scan方法传递的pointer参数,可以使用ctx来传递到最底层来完成赋值。
- 关于hook,改动底层的逻辑过后会对目前的
HookSelectInput.Next方法不兼容,因为用户可能会依赖Next方法的返回值,对数据做一些处理之类的,而改动后的逻辑不在使用返回值来返回数据,可能需要增加一个新的api或者新的HookSelectInput。 - 可以对Scan方法做些增强,如 参数支持基础类型的切片,且只支持一维类型的切片。
Next方法里面的缓存逻辑可能需要做些更改- 表字段类型到go语言类型的转换暂时先用gconv.Convert来做。
- 改动过后,建议废弃掉One,All之类的api,全部使用Scan方法来做赋值,这样不用再经过中间变量来回复制
从Scan方法一直到最低层的RowsToResult的调用链
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
- The pointer parameter currently passed from the Scan method can be passed to the bottom layer using ctx to complete the assignment.
- Regarding hooks, changing the underlying logic will make it incompatible with the current
HookSelectInput.Nextmethod, because users may rely on the return value of the Next method to do some processing on the data, and the changed logic will no longer be used. To return data by returning a value, you may need to add a new API or a new HookSelectInput. - Some enhancements can be made to the Scan method. For example, the parameters support basic type slices and only support one-dimensional type slices.
- The caching logic in the
Nextmethod may need to be changed. - For the time being, gconv.Convert is used to convert table field types to go language types.
- After the changes, it is recommended to abandon APIs such as One and All, and all use the Scan method for assignment, so that there is no need to copy back and forth through intermediate variables.
The call chain from the Scan method to the lowest level RowsToResult
@gqcn 强哥怎么看呢?
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@gqcn What do you think of Brother Qiang?
关于(*gdb.HookSelectInput).Next 方法不兼容,目前我想到了以下几种解决方案
- Next 方法的参数返回值全部不变,在Next 方法内部增加一个变量来判断用户是否调用了Next,如果是用户主动调用的,则把所有的值重新复制一份返回出去,或者使用原来的api去做底层查询
- Next 方法的参数返回值全部不变,为gdb.Result增加一些新的api,遍历或者设置其中的一些值,全部使用新的api来做
- 使用新的api来代替Next方法。
其实可以1和3结合一下,提供新的api,同时旧的Next方法不变,在注释上加上Deprecated标记, 然后多提倡用户使用新的api来做。
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Regarding the incompatibility of the (*gdb.HookSelectInput).Next method, I currently have the following solutions in mind:
- All the parameter return values of the Next method remain unchanged. Add a variable inside the Next method to determine whether the user has called Next. If the user actively calls Next, copy all the values and return them, or use the original ones. api to do underlying queries
- The parameter return values of the Next method remain unchanged. Add some new APIs to gdb.Result, traverse or set some of the values, and use the new APIs to do everything.
- Use the new API to replace the Next method.
In fact, you can combine 1 and 3 to provide a new API. At the same time, the old Next method remains unchanged, and the Deprecated mark is added to the annotation. Then encourage users to use the new API.