packages feed

beam-duckdb 0.3.1.0 → 0.3.2.0

raw patch · 5 files changed

+48/−42 lines, 5 filesdep ~duckdb-simplePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: duckdb-simple

API changes (from Hackage documentation)

+ Database.Beam.DuckDB: -- table <tt>tbl</tt> that violates a constraint.
+ Database.Beam.DuckDB: -- to occur
+ Database.Beam.DuckDB: -- | What to do when an <tt>INSERT</tt> statement inserts a row into the
- Database.Beam.DuckDB: data family SqlConflictTarget be (table :: Type -> Type -> Type)
+ Database.Beam.DuckDB: data family SqlConflictAction be (table :: Type -> Type -> Type)

Files

CHANGELOG.md view
@@ -1,6 +1,10 @@ # Revision history for beam-duckdb -## 0.3.1.0 -- unreleased+## 0.3.2.0 -- 2026-11-19++* `duckdb-simple-1.0` or later is now required.++## 0.3.1.0 -- 2026-05-13  * Added support for `beam-migrate`: the new `Database.Beam.DuckDB.Migrate`   module exposes a `migrationBackend :: BeamMigrationBackend DuckDB DuckDBM`
README.md view
@@ -11,15 +11,6 @@ `beam-duckdb` is the most recent backend for beam; do not hesitate to raise an issue if you'd like us to add support for something that isn't currently covered! -## Installation--The underlying duckdb-ffi needs to link to libduckdb. By default the installation assumes:--* The duckdb files are in `/usr/lib/duckdb`-* You're using duckdb 1.4.*--For Linux you can install a blessed version of duckdb in the correct path by cloning the duckdb-haskell repo and running `make install` in the [duckdb-ffi cbits folder](https://github.com/Tritlo/duckdb-haskell/tree/main/duckdb-ffi/cbits).- ## Example  From the project root directory, execute `cabal run ./examples/ExamScores.hs`.
beam-duckdb.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               beam-duckdb-version:            0.3.1.0+version:            0.3.2.0 synopsis:           DuckDB backend for Beam description:        Beam driver for DuckDB, an analytics-focused open-source in-process database. license:            MIT@@ -49,14 +49,12 @@                       Database.Beam.DuckDB.Syntax.Extensions.Copy                       Database.Beam.DuckDB.Syntax.Extensions.DataSource                       Database.Beam.DuckDB.Syntax.Extensions.InsertOnConflict-    build-depends:    aeson >=1.0 && <2.3+    build-depends:    aeson >=1.0 && <2.4                     , base >=4.11 && <5                     , beam-core >=0.11.1 && <0.12                     , beam-migrate ^>=0.6                     , bytestring >=0.10 && <0.13-                    -- Version 0.1.5.0 contained a broken change (RowParser constructor not exposed)-                    -- which was reverted in version 0.1.5.1-                    , duckdb-simple (>=0.1.2 && <0.1.5) || (>=0.1.5.1 && <0.1.6)+                    , duckdb-simple >=1.0 && <1.1                     , dlist >=0.8 && <1.1                     , free >=4.12 && <5.3                     , hashable >=1.1 && <1.6
src/Database/Beam/DuckDB/Connection.hs view
@@ -22,13 +22,14 @@   ) where +import Control.Applicative ((<|>)) import Control.Exception (SomeException (..)) import Control.Monad (void) import Control.Monad.Free.Church (runF) import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.Trans.Class (lift)-import Control.Monad.Trans.Reader (ReaderT (..), ask)-import Control.Monad.Trans.State.Strict (StateT (..), get, put)+import Control.Monad.Trans.Reader (ReaderT (..), ask, mapReaderT)+import Control.Monad.Trans.State.Strict (gets, mapStateT) import Data.Coerce (coerce) import qualified Data.DList as DL import Data.Data (cast)@@ -59,8 +60,8 @@     DuckDBCopyToSyntax (..),   ) import Database.DuckDB.Simple (Connection, FromRow, Query (Query), ResultError (..), RowParser, ToField (toField), ToRow (toRow), bind, execute, nextRow, withStatement)+import Database.DuckDB.Simple.Conversion (conversionError, mapConversionErrors) import Database.DuckDB.Simple.FromRow (FromRow (..), RowParser (..), field)-import Database.DuckDB.Simple.Ok (Ok (..))  -- | 'MonadBeam' instance inside which DuckDB queries are run. See the -- <https://haskell-beam.github.io/beam/ user guide> for more information@@ -184,27 +185,14 @@       finish = pure        step :: forall a'. FromBackendRowF DuckDB (RowParser a') -> RowParser a'-      step (ParseOneField next) =-        RowParser $ ReaderT $ \ro -> StateT $ \st@(col, _) ->-          case runStateT (runReaderT (runRowParser field) ro) st of-            Ok (x, st') -> runStateT (runReaderT (runRowParser (next x)) ro) st'-            Errors errs -> Errors (mapMaybe (translateErrors (Just col)) errs)-      step (Alt (FromBackendRowM a) (FromBackendRowM b) next) = do-        RowParser $ do-          let RowParser a' = runF a finish step-              RowParser b' = runF b finish step--          st <- lift get-          ro <- ask-          case runStateT (runReaderT a' ro) st of-            Ok (ra, st') -> do-              lift $ put st'-              runRowParser (next ra)-            Errors aErrs ->-              case runStateT (runReaderT b' ro) st of-                Ok (rb, st') -> do-                  lift $ put st'-                  runRowParser (next rb)-                Errors bErrs ->-                  lift (lift (Errors (aErrs ++ bErrs)))-      step (FailParseWith err) = RowParser (lift (lift (Errors [SomeException err])))+      step (ParseOneField next) = do+        col <- RowParser (lift (gets fst))+        x <-+          RowParser $+            mapReaderT+              (mapStateT (mapConversionErrors (mapMaybe (translateErrors (Just col)))))+              (runRowParser field)+        next x+      step (Alt (FromBackendRowM a) (FromBackendRowM b) next) =+        (runF a finish step <|> runF b finish step) >>= next+      step (FailParseWith err) = RowParser (lift (lift (conversionError err)))
tests/Database/Beam/DuckDB/Test/Query.hs view
@@ -12,6 +12,7 @@ module Database.Beam.DuckDB.Test.Query (tests) where  import Control.Monad (void)+import Data.Functor ((<&>)) import Data.Int (Int32) import Data.List (nub, nubBy, sort, sortOn) import Data.Text (Text)@@ -130,6 +131,7 @@           testGroup             "CTE"             [ testCommonTableExpression,+              testEmptyCommonTableExpression,               testMultipleCommonTableExpressions,               testRecursiveCommonTableExpression             ],@@ -420,6 +422,29 @@                 pure (_userName u, total)        rows @?= [("Alice", 3), ("Bob", 1)]++-- Regression test for https://github.com/haskell-beam/beam/issues/760+--+-- Note that this is testing functionality from 'beam-core', but the MockSqlBackend+-- isn't powerful enough to express this test+testEmptyCommonTableExpression :: TestTree+testEmptyCommonTableExpression = testCase "No common table expression in `selectWith` is equivalent to `select`" $ do+  let users =+        [ User 1 "Alice" 30,+          User 2 "Bob" 25,+          User 3 "Charlie" 35+        ]+  withTestDb users [] [] $ \conn ->+    do+      rows <-+        runBeamDuckDB conn+          $ runSelectReturningList+            . selectWith+            . pure+          $ all_ (_dbUsers testDb)+            <&> _userName++      rows @?= ["Alice", "Bob", "Charlie"]  testMultipleCommonTableExpressions :: TestTree testMultipleCommonTableExpressions = testCase "Multiple common table expressions" $ do