module Units.SnippetSpec whereimport Hasql.Connection qualified as Connectionimport Hasql.Decoders qualified as Decodersimport Hasql.DynamicStatements.Snippet qualified as Snippetimport Hasql.Session qualified as Sessionimport Preludeimport Test.Hspecspec :: SpecWith Connection.Connectionspec = do describe "Select substring" do it "Works" \connection -> do let sample string from to = let snippet = "select substring(" <> Snippet.param @Text string <> foldMap (mappend " from " . Snippet.param @Int32) from <> foldMap (mappend " for " . Snippet.param @Int32) to <> ")" decoder = Decoders.singleRow (Decoders.column (Decoders.nonNullable Decoders.text)) in Connection.use connection (Session.statement () (Snippet.toStatement snippet decoder)) in do shouldBe (Right "bc") =<< sample "abcd" (Just 2) (Just 2) shouldBe (Right "bcd") =<< sample "abcd" (Just 2) (Just 3) shouldBe (Right "abc") =<< sample "abcd" Nothing (Just 3) shouldBe (Right "bcd") =<< sample "abcd" (Just 2) Nothing