Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some ideas on improving the Scan method of orm #3538

Open
wln32 opened this issue Apr 24, 2024 · 5 comments · May be fixed by #3557
Open

Some ideas on improving the Scan method of orm #3538

wln32 opened this issue Apr 24, 2024 · 5 comments · May be fixed by #3557

Comments

@wln32
Copy link
Member

wln32 commented Apr 24, 2024

  1. 目前从Scan方法传递的pointer参数,可以使用ctx来传递到最底层来完成赋值。
  2. 关于hook,改动底层的逻辑过后会对目前的HookSelectInput.Next方法不兼容,因为用户可能会依赖Next方法的返回值,对数据做一些处理之类的,而改动后的逻辑不在使用返回值来返回数据,可能需要增加一个新的api或者新的HookSelectInput。
  3. 可以对Scan方法做些增强,如 参数支持基础类型的切片,且只支持一维类型的切片。
  4. Next方法里面的缓存逻辑可能需要做些更改
  5. 表字段类型到go语言类型的转换暂时先用gconv.Convert来做。
  6. 改动过后,建议废弃掉One,All之类的api,全部使用Scan方法来做赋值,这样不用再经过中间变量来回复制

从Scan方法一直到最低层的RowsToResult的调用链
调用链

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


  1. The pointer parameter currently passed from the Scan method can be passed to the bottom layer using ctx to complete the assignment.
  2. Regarding hooks, changing the underlying logic will make it incompatible with the current HookSelectInput.Next method, 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.
  3. Some enhancements can be made to the Scan method. For example, the parameters support basic type slices and only support one-dimensional type slices.
  4. The caching logic in the Next method may need to be changed.
  5. For the time being, gconv.Convert is used to convert table field types to go language types.
  6. 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
Call chain

@Issues-translate-bot Issues-translate-bot changed the title 关于orm的Scan方法改进的一些想法 Some ideas on improving the Scan method of orm Apr 24, 2024
@wln32
Copy link
Member Author

wln32 commented Apr 24, 2024

@gqcn 强哥怎么看呢?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn What do you think of Brother Qiang?

@wln32 wln32 linked a pull request Apr 24, 2024 that will close this issue
@wln32
Copy link
Member Author

wln32 commented Apr 27, 2024

关于(*gdb.HookSelectInput).Next 方法不兼容,目前我想到了以下几种解决方案

  1. Next 方法的参数返回值全部不变,在Next 方法内部增加一个变量来判断用户是否调用了Next,如果是用户主动调用的,则把所有的值重新复制一份返回出去,或者使用原来的api去做底层查询
  2. Next 方法的参数返回值全部不变,为gdb.Result增加一些新的api,遍历或者设置其中的一些值,全部使用新的api来做
  3. 使用新的api来代替Next方法。

其实可以1和3结合一下,提供新的api,同时旧的Next方法不变,在注释上加上Deprecated标记,
然后多提倡用户使用新的api来做。

@Issues-translate-bot
Copy link

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:

  1. 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
  2. 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.
  3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants