commit 92d7f2f45932a28159f80e9ece95b2f6d6272002
parent e606a6740451d2c24e725e638d04af67c35941f7
Author: srfsh <dev@srf.sh>
Date: Fri, 23 Sep 2022 16:54:36 +0300
Zenflows.DB.Filter: introduce filtering helpers
Diffstat:
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/zenflows/db/filter.ex b/src/zenflows/db/filter.ex
@@ -0,0 +1,28 @@
+# Zenflows is designed to implement the Valueflows vocabulary,
+# written and maintained by srfsh <info@dyne.org>.
+# Copyright (C) 2021-2022 Dyne.org foundation <foundation@dyne.org>.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+defmodule Zenflows.DB.Filter do
+@moduledoc "Filtering helpers for Filter modules."
+
+@type params() :: %{atom() => term()}
+@type error() :: {:error, Changeset.t()}
+@type result() :: {:ok, Query.t()} | error()
+
+def escape_like(v) do
+ Regex.replace(~r/\\|%|_/, v, &"\\#{&1}")
+end
+end