Created
February 16, 2021 05:42
-
-
Save mreigen/dab1962a2c42edfc7780c29d6024a4a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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