无法删除并从ETS表中选择

发布于 2025-02-02 03:41:54 字数 293 浏览 3 评论 0原文

我很难从ET中检索和删除记录。

在插入它们之后:

:ets.insert(
  :table_name,
  {id, location, [name, x, z]}
)

我无法像这样删除它们:

:ets.delete(:table_name, id) 

我也尝试过,这没有返回任何内容。

:ets.match(:table_name, {id, location, '_'}) 

I am having trouble retrieving and deleting records from ETS.

After inserting them like:

:ets.insert(
  :table_name,
  {id, location, [name, x, z]}
)

I am unable to delete them like so:

:ets.delete(:table_name, id) 

I have also tried and this doesn't return anything.

:ets.match(:table_name, {id, location, '_'}) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺孤伤于心 2025-02-09 03:41:54

如果要在ET(和DETS)周围使用长生不老药包装器,则可以使用 pockets

iex> Pockets.new(:table_name)
{:ok, :table_name}
iex> Pockets.put(:table_name, :id, "Foo")
:table_name
iex> Pockets.get(:table_name, :id)
"Foo"

If you want to use an Elixir wrapper around ETS (and DETS), you can use pockets:

iex> Pockets.new(:table_name)
{:ok, :table_name}
iex> Pockets.put(:table_name, :id, "Foo")
:table_name
iex> Pockets.get(:table_name, :id)
"Foo"
微凉徒眸意 2025-02-09 03:41:54

ETS 的内容:

ets = :ets.new(:table_name, [])

:ets.insert(ets, {1, 2, ["foo", 3, 4]})       
#⇒ true

:ets.foldl(&[&1|&2], [], ets)
#⇒ [{1, 2, ["foo", 3, 4]}]

您始终

:ets.delete ets, 1
#⇒ true

可以使用:ETS.MATCH/2应该使用 Atoms elixir erlang 在如何表示它们中)指定要返回的内容。

:ets.match(ets, {:_, :_, :'$1'})  
#⇒ [[["foo", 3, 4]]]

:ets.match(ets, {1, :'$1', :'$2'})
#⇒ [[2, ["foo", 3, 4]]]

You always can review the content of :ets with :ets.foldl/3

ets = :ets.new(:table_name, [])

:ets.insert(ets, {1, 2, ["foo", 3, 4]})       
#⇒ true

:ets.foldl(&[&1|&2], [], ets)
#⇒ [{1, 2, ["foo", 3, 4]}]

:ets.delete/2 works out of the box:

:ets.delete ets, 1
#⇒ true

For :ets.match/2 one should use atoms ( differs from in how to denote them) and specify what to return back.

:ets.match(ets, {:_, :_, :'$1'})  
#⇒ [[["foo", 3, 4]]]

:ets.match(ets, {1, :'$1', :'$2'})
#⇒ [[2, ["foo", 3, 4]]]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文