Skip to content

Question about find with key #34

@dustinsmith1024

Description

@dustinsmith1024

Is there a better way to find something by a name/id? This below works, but seems like the named parameter way should work too.

def find(email) do
    # Works fine, but I want to use the key
    # Diplomat.Query.new("select * from `User` where email_address = @email", %{email: email} )

    "select * from User where __key__ = KEY(User, \"#{email}\")"
    |> Diplomat.Query.new
    |> Diplomat.Query.execute
    |> hd
  end

When I use the names params:

 def find2(email) do
    Diplomat.Query.new("select * from User where __key__ = KEY(User, @email)", %{email: email})
    |> Diplomat.Query.execute
  end

I get:

iex(1)> u = User.find2("[email protected]")
{:error,
 %Diplomat.Proto.Status{
   code: 3,
   details: [],
   message: "Encountered \"@email\" at line 1, column 46.\nWas expecting one of:\n    <INTEGER> ...\n    <SINGLE_QUOTE_STRING> ...\n    <DOUBLE_QUOTE_STRING> ...\n    "
 }}
iex(2)>

Semi-new to Google Data Store so I could be missing something simple.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions