From 30fff94a2660756c88fc5dadf1d4840bf59b177a Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 18 Dec 2023 09:04:55 -0600 Subject: [PATCH] feat: isReferenced --- spago.yaml | 1 + src/Data.Postgres.Query.Builder.purs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spago.yaml b/spago.yaml index 057e339..95ebeed 100644 --- a/spago.yaml +++ b/spago.yaml @@ -10,6 +10,7 @@ package: - effect - either - exceptions + - foldable-traversable - foreign - fork - maybe diff --git a/src/Data.Postgres.Query.Builder.purs b/src/Data.Postgres.Query.Builder.purs index 8edd317..afd5e54 100644 --- a/src/Data.Postgres.Query.Builder.purs +++ b/src/Data.Postgres.Query.Builder.purs @@ -2,8 +2,9 @@ module Data.Postgres.Query.Builder where import Prelude -import Control.Monad.State (StateT, modify, runStateT) +import Control.Monad.State (StateT, get, modify, runStateT) import Data.Array as Array +import Data.Foldable (any, elem) import Data.Set (Set) import Data.Set as Set import Data.Tuple.Nested (type (/\)) @@ -18,6 +19,11 @@ runBuilder = flip runStateT { params: [], refs: Set.empty } reference :: forall m. Monad m => String -> BuilderT m Unit reference k = void $ modify (\s@{ refs } -> s { refs = Set.insert k refs }) +isReferenced :: forall m. Monad m => Array String -> BuilderT m Boolean +isReferenced ts = do + { refs } <- get + pure $ any (flip elem ts) refs + param :: forall m a. Monad m => ToSQLValue a => a -> BuilderT m String param p = do