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

lua 多主键表(独立索引)生成代码问题 #132

Closed
zengdonghai opened this issue Apr 18, 2024 · 6 comments
Closed

lua 多主键表(独立索引)生成代码问题 #132

zengdonghai opened this issue Apr 18, 2024 · 6 comments

Comments

@zengdonghai
Copy link

image
image
我想配置一个配置表的Id,Domain两个为独立的键,生成对应独立的map映射表,在lua的表示中,只生成上图这种list的格式,这种多主键表(独立索引)配置方式,在lua貌似不生效

@zengdonghai
Copy link
Author

image
图f发错了,对应生成了这种list格式,

@zengdonghai
Copy link
Author

image
理想是应该这种map的格式。当然这里还可以优化,value的引用

@pirunxi
Copy link
Contributor

pirunxi commented Apr 18, 2024

这是已知问题,很多语言并没有内置的多key索引的支持,因此由开发者自己选择合适的实现。写一个make_index2函数就能较好达到效果。

@pirunxi pirunxi closed this as completed Apr 18, 2024
@zengdonghai
Copy link
Author

那是需要自己修改代码生成的源码咯?如果是这样那我自己定制一个生成器吧。

@pirunxi
Copy link
Contributor

pirunxi commented Apr 18, 2024

我觉得没必要改源码。 你实现一个make_index函数将列表转换为你想要的索引方式即可 ,代码类似这样

function make_index(t, key1, key2)
  
   local nt = {}
   for _, v in ipairs(t) do 
     nt[v[key1]] = v
     nt[v[key2]] = v
  end
    return nt
end

@zengdonghai
Copy link
Author

了解,谢谢!

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

No branches or pull requests

2 participants