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

Pass arguments to deftable #66

Open
sheharyarn opened this issue Apr 6, 2017 · 4 comments
Open

Pass arguments to deftable #66

sheharyarn opened this issue Apr 6, 2017 · 4 comments

Comments

@sheharyarn
Copy link
Contributor

sheharyarn commented Apr 6, 2017

I'm trying to set the attributes of a table from a variable / module_attribute in the deftable macro, but it raises an exception instead.

use Amnesia

defdatabase MyApp.DB do
  @attrs [:id, :a, :b, :c]

  deftable SomeTable, @attrs, type: :bag do
  end 
end

I also tried using unquote(@attrs) since it's a macro but that doesn't work either. Is there some way I can get this to work? (This is just an example, the attributes need to be loaded from another module during compile-time).

This is the error I get:

Compiling 1 file (.ex)

== Compilation error on file lib/mnesia.ex ==
** (ArgumentError) argument error
    :erlang.length({:@, [line: 6], [{:attrs, [line: 6], nil}]})
    lib/amnesia/table/definition.ex:63: Amnesia.Table.Definition.define/4
    expanding macro: Amnesia.Database.deftable/4
    lib/db.ex:6: MyApp.DB (module)
@meh
Copy link
Owner

meh commented Apr 6, 2017

What's the error in the unquote(@attrs) case? I honestly don't know how to make that work right now but my brain tells me "unquote fragments" and "using bind_quoted somewhere in defdatabase/deftable" are part of the answer.

@sheharyarn
Copy link
Contributor Author

This is the error when I try with unquote(@attrs):

Compiling 1 file (.ex)

== Compilation error on file lib/mnesia.ex ==
** (ArgumentError) argument error
    :erlang.length({:unquote, [line: 6], [{:@, [line: 6], [{:attrs, [line: 6], nil}]}]})
    lib/amnesia/table/definition.ex:63: Amnesia.Table.Definition.define/4
    expanding macro: Amnesia.Database.deftable/4
    lib/db.ex:6: MyApp.DB (module)

@ourway
Copy link

ourway commented Jul 28, 2017

Any updates?

@meh
Copy link
Owner

meh commented Jul 28, 2017

@ourway I played around with it but didn't figure out a way to make it work :(

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

3 participants