packages feed

selda 0.1.4.0 → 0.1.4.1

raw patch · 6 files changed

+23/−10 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Database.Selda.Backend: [dbIdentifier] :: SeldaBackend -> Text
- Database.Selda: setLocalCache :: MonadSelda m => Int -> m ()
+ Database.Selda: setLocalCache :: MonadIO m => Int -> m ()
- Database.Selda.Backend: SeldaBackend :: QueryRunner (Int, [[SqlValue]]) -> QueryRunner Int -> (Text -> [ColAttr] -> Maybe Text) -> Text -> SeldaBackend
+ Database.Selda.Backend: SeldaBackend :: QueryRunner (Int, [[SqlValue]]) -> QueryRunner Int -> (Text -> [ColAttr] -> Maybe Text) -> Text -> Text -> SeldaBackend

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for selda +## 0.1.4.1 -- 2017-05-04++* Fix cache consistency bug in the presence of multiple databases.++ ## 0.1.4.0 -- 2017-05-04  * Add uniqueness constraints and foreign keys.
README.md view
@@ -19,12 +19,12 @@  * Monadic interface: no need to be a category theory wizard just to write a few   database queries.-* Portable: fully functional backends for SQLite and PostgreSQL.+* Portable: backends for SQLite and PostgreSQL. * Generic: easy integration with your existing Haskell types. * Creating, dropping and querying tables using type-safe database schemas. * Typed query language with products, filtering, joins and aggregation. * Inserting, updating and deleting rows from tables.-* Transaction support.+* Transactions, uniqueness constraints and foreign keys. * Configurable, automatic, consistent in-process caching of query results. * Lightweight and modular: non-essential features are optional or split into   add-on packages.@@ -566,7 +566,7 @@ in-process caching. It is perfectly fine, however, to have multiple *threads* within the same application modifying the same database as long as they're all using Selda-to do it, as the cache shared between all Selda computations+to do it, as the cache is shared between all Selda computations running in the same process.  
selda.cabal view
@@ -1,5 +1,5 @@ name:                selda-version:             0.1.4.0+version:             0.1.4.1 synopsis:            Type-safe, high-level EDSL for interacting with relational databases. description:         This package provides an EDSL for writing portable, type-safe, high-level                      database code. Its feature set includes querying and modifying databases,
src/Database/Selda/Backend.hs view
@@ -51,6 +51,11 @@     -- | The keyword that represents the default value for auto-incrementing     --   primary keys.   , defaultKeyword :: Text++    -- | A string uniquely identifying the database used by this invocation+    --   of the backend. This could be, for instance, a PostgreSQL connection+    --   string or the absolute path to an SQLite file.+  , dbIdentifier   :: Text }  data SeldaState = SeldaState
src/Database/Selda/Caching.hs view
@@ -20,7 +20,7 @@ import Database.Selda.SQL (Param (..)) import Database.Selda.Types (TableName) -type CacheKey = (Text, [Param])+type CacheKey = (Text, Text, [Param])  #ifdef NO_LOCALCACHE 
src/Database/Selda/Frontend.hs view
@@ -152,7 +152,8 @@  -- | Set the maximum local cache size to @n@. A cache size of zero disables --   local cache altogether. Changing the cache size will also flush all---   entries.+--   entries. Note that the cache is shared among all Selda computations running+--   within the same process. -- --   By default, local caching is turned off. --@@ -160,24 +161,26 @@ --   database, ONLY under the assumption that no other process will modify it. --   Also note that the cache is shared between ALL Selda computations running --   within the same process.-setLocalCache :: MonadSelda m => Int -> m ()+setLocalCache :: MonadIO m => Int -> m () setLocalCache = liftIO . setMaxItems  -- | Build the final result from a list of result columns. queryWith :: forall s m a. (MonadSelda m, Result a)           => QueryRunner (Int, [[SqlValue]]) -> Query s a -> m [Res a] queryWith qr q = do-    mres <- liftIO $ cached qry+    db <- dbIdentifier <$> seldaBackend+    let cacheKey = (db, qs, ps)+    mres <- liftIO $ cached cacheKey     case mres of       Just res -> do         return res       _        -> do         res <- fmap snd . liftIO $ uncurry qr qry         let res' = mkResults (Proxy :: Proxy a) res-        liftIO $ cache tables qry res'+        liftIO $ cache tables cacheKey res'         return res'   where-    (tables, qry) = compileWithTables q+    (tables, qry@(qs, ps)) = compileWithTables q  -- | Generate the final result of a query from a list of untyped result rows. mkResults :: Result a => Proxy a -> [[SqlValue]] -> [Res a]