Skip to content

Instantly share code, notes, and snippets.

@mreigen
Created February 16, 2021 05:42
Show Gist options
  • Save mreigen/dab1962a2c42edfc7780c29d6024a4a5 to your computer and use it in GitHub Desktop.
Save mreigen/dab1962a2c42edfc7780c29d6024a4a5 to your computer and use it in GitHub Desktop.
import Ecto.Query
...
defmacro store_items_not_exist(store_items_table_name, store_id, item_name) do
args = [
"NOT EXISTS (SELECT * FROM #{store_items_table_name} item WHERE item.store_id = ? AND item.name == ?)",
store_id,
item_name
]
quote do: fragment(unquote_splicing(args))
end
from(store in Store,
where: store_items_not_exist("appliances", store.id, "VCR player"),
where: store_items_not_exist("game_consoles", store.id, "Sega Genesis")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment