packages feed

persistent-sqlite 2.0.1 → 2.0.3

raw patch · 2 files changed

+26/−15 lines, 2 filesdep ~persistent

Dependency ranges changed: persistent

Files

Database/Persist/Sqlite.hs view
@@ -122,7 +122,13 @@     Nothing ->       ISRInsertGet ins sel         where-          sel = "SELECT last_insert_rowid()"+          sel = T.concat+              [ "SELECT "+              , escape $ sqlIdName ent+              , " FROM "+              , escape $ entityDB ent+              , " WHERE _ROWID_=last_insert_rowid()"+              ]           ins = T.concat               [ "INSERT INTO "               , escape $ entityDB ent@@ -209,20 +215,20 @@ safeToRemove :: EntityDef -> DBName -> Bool safeToRemove def (DBName colName)     = any (elem "SafeToRemove" . fieldAttrs)-    $ filter ((== (DBName colName)) . fieldDB)+    $ filter ((== DBName colName) . fieldDB)     $ entityFields def  getCopyTable :: [EntityDef]              -> (Text -> IO Statement)              -> EntityDef              -> IO [(Bool, Text)]-getCopyTable allDefs getter val = do+getCopyTable allDefs getter def = do     stmt <- getter $ T.concat [ "PRAGMA table_info(", escape table, ")" ]     oldCols' <- with (stmtQuery stmt []) ($$ getCols)     let oldCols = map DBName $ filter (/= "id") oldCols' -- need to update for table id attribute ?     let newCols = filter (not . safeToRemove def) $ map cName cols     let common = filter (`elem` oldCols) newCols-    let id_ = entityID val+    let id_ = sqlIdName def     return [ (False, tmpSql)            , (False, copyToTemp $ id_ : common)            , (common /= filter (not . safeToRemove def) oldCols, dropOld)@@ -231,8 +237,6 @@            , (False, dropTmp)            ]   where--    def = val     getCols = do         x <- CL.head         case x of@@ -243,7 +247,7 @@             Just y -> error $ "Invalid result from PRAGMA table_info: " ++ show y     table = entityDB def     tableTmp = DBName $ unDBName table <> "_backup"-    (cols, uniqs, _) = mkColumns allDefs val+    (cols, uniqs, _) = mkColumns allDefs def     cols' = filter (not . safeToRemove def . cName) cols     newSql = mkCreateTable False def (cols', uniqs)     tmpSql = mkCreateTable True def { entityDB = tableTmp } (cols', uniqs)@@ -281,7 +285,7 @@         , T.drop 1 $ T.concat $ map sqlColumn cols         , ", PRIMARY KEY "         , "("-        , T.intercalate "," $ map (escape . fieldDB) $ primaryFields pdef+        , T.intercalate "," $ map (escape . fieldDB) $ compositeFields pdef         , ")"         , ")"         ]@@ -291,13 +295,21 @@         , " TABLE "         , escape $ entityDB entity         , "("-        , escape $ entityID entity-        , " INTEGER PRIMARY KEY"+        , escape $ sqlIdName entity+        , " "+        , showSqlType $ fieldSqlType $ entityId entity+        ," PRIMARY KEY"+        , mayDefault $ defaultAttribute $ fieldAttrs $ entityId entity         , T.concat $ map sqlColumn cols         , T.concat $ map sqlUnique uniqs         , ")"         ] +mayDefault :: Maybe Text -> Text+mayDefault def = case def of+    Nothing -> ""+    Just d -> " DEFAULT " <> d+ sqlColumn :: Column -> Text sqlColumn (Column name isNull typ def _cn _maxLen ref) = T.concat     [ ","@@ -305,9 +317,7 @@     , " "     , showSqlType typ     , if isNull then " NULL" else " NOT NULL"-    , case def of-        Nothing -> ""-        Just d -> " DEFAULT " <> d+    , mayDefault def     , case ref of         Nothing -> ""         Just (table, _) -> " REFERENCES " <> escape table
persistent-sqlite.cabal view
@@ -1,5 +1,5 @@ name:            persistent-sqlite-version:         2.0.1+version:         2.0.3 license:         MIT license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>@@ -24,7 +24,7 @@     build-depends:   base                    >= 4         && < 5                    , bytestring              >= 0.9.1                    , transformers            >= 0.2.1-                   , persistent              >= 2.0.1     && < 2.1+                   , persistent              >= 2.0.3     && < 2.1                    , monad-control           >= 0.2                    , containers              >= 0.2                    , text                    >= 0.7@@ -39,6 +39,7 @@         extra-libraries: sqlite3     else         c-sources:   cbits/sqlite3.c+        cc-options:  -fPIC      if !os(windows)         extra-libraries: pthread