selda-sqlite 0.1.7.1 → 0.1.7.2
raw patch · 3 files changed
+16/−33 lines, 3 filesdep ~bytestringdep ~time
Dependency ranges changed: bytestring, time
Files
- LICENSE +0/−21
- selda-sqlite.cabal +3/−4
- src/Database/Selda/SQLite.hs +13/−8
− LICENSE
@@ -1,21 +0,0 @@-MIT License--Copyright (c) 2017-2019 Anton Ekblad--Permission is hereby granted, free of charge, to any person obtaining a copy-of this software and associated documentation files (the "Software"), to deal-in the Software without restriction, including without limitation the rights-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell-copies of the Software, and to permit persons to whom the Software is-furnished to do so, subject to the following conditions:--The above copyright notice and this permission notice shall be included in all-copies or substantial portions of the Software.--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE-SOFTWARE.
selda-sqlite.cabal view
@@ -1,11 +1,10 @@ name: selda-sqlite-version: 0.1.7.1+version: 0.1.7.2 synopsis: SQLite backend for the Selda database EDSL. description: Allows the Selda database EDSL to be used with SQLite databases. homepage: https://github.com/valderman/selda license: MIT-license-file: LICENSE author: Anton Ekblad maintainer: anton@ekblad.cc category: Database@@ -30,11 +29,11 @@ , text >=1.0 && <1.3 if !flag(haste) build-depends:- bytestring >=0.10 && <0.11+ bytestring >=0.10 && <0.12 , direct-sqlite >=2.2 && <2.4 , directory >=1.2.2 && <1.4 , exceptions >=0.8 && <0.11- , time >=1.5 && <1.10+ , time >=1.5 && <1.12 , uuid-types >=1.0 && <1.1 hs-source-dirs: src
src/Database/Selda/SQLite.hs view
@@ -15,6 +15,7 @@ import Control.Monad.Catch import Data.ByteString.Lazy (toStrict) import Data.Dynamic+import Data.Int (Int64) import Data.Text as Text (pack, toLower, take) import Data.Time (FormatTime, formatTime, defaultTimeLocale) import Data.UUID.Types (toByteString)@@ -91,7 +92,8 @@ ixs <- mapM indexInfo . snd . snd =<< sqliteQueryRunner db indexes [] colInfos <- mapM (describe fks ixs cs) cols return $ TableInfo- { tableColumnInfos = colInfos+ { tableInfoName = mkTableName tbl+ , tableColumnInfos = colInfos , tableUniqueGroups = [ map mkColName names | (names, "u") <- ixs@@ -115,6 +117,7 @@ ixinfo name = mconcat ["PRAGMA index_info(", name, ");"] toTypeRep _ "text" = Right TText+ toTypeRep _ "double precision" = Right TFloat toTypeRep _ "double" = Right TFloat toTypeRep _ "boolean" = Right TBool toTypeRep _ "datetime" = Right TDateTime@@ -122,7 +125,8 @@ toTypeRep _ "time" = Right TTime toTypeRep _ "blob" = Right TBlob toTypeRep True "integer" = Right TRowID- toTypeRep pk s | Text.take 3 s == "int" = Right $ if pk then TRowID else TInt+ toTypeRep pk s | Text.take 6 s == "bigint" = Right $ if pk then TRowID else TInt64+ toTypeRep pk s | Text.take 3 s == "int" = Right $ if pk then TRowID else TInt32 toTypeRep _ typ = Left typ indexInfo [_, SqlString ixname, _, SqlString itype, _] = do@@ -132,8 +136,8 @@ indexInfo _ = do error "unreachable" - describe fks ixs cs [_, SqlString name, SqlString ty, SqlInt nonnull, _, SqlInt pk] = do- let ty' = toLower ty+ describe fks ixs cs [_, SqlString name, SqlString ty, SqlInt64 nonnull, _, SqlInt64 pk] = do+ let ty' = Text.toLower ty return $ ColumnInfo { colName = mkColName name , colType = toTypeRep (pk == 1) ty'@@ -176,7 +180,7 @@ Left e@(SQLError{}) -> throwM (SqlError (show e)) Right res -> return (snd res) -sqliteQueryRunner :: Database -> QueryRunner (Int, (Int, [[SqlValue]]))+sqliteQueryRunner :: Database -> QueryRunner (Int64, (Int, [[SqlValue]])) sqliteQueryRunner db qry params = do eres <- try $ do stm <- prepare db qry@@ -186,7 +190,7 @@ Left e@(SQLError{}) -> throwM (SqlError (show e)) Right res -> return res -sqliteRunStmt :: Database -> Statement -> [Param] -> IO (Int, (Int, [[SqlValue]]))+sqliteRunStmt :: Database -> Statement -> [Param] -> IO (Int64, (Int, [[SqlValue]])) sqliteRunStmt db stm params = do bind stm [toSqlData p | Param p <- params] rows <- getRows stm []@@ -205,7 +209,8 @@ return $ reverse acc toSqlData :: Lit a -> SQLData-toSqlData (LInt i) = SQLInteger $ fromIntegral i+toSqlData (LInt32 i) = SQLInteger $ fromIntegral i+toSqlData (LInt64 i) = SQLInteger $ fromIntegral i toSqlData (LDouble d) = SQLFloat d toSqlData (LText s) = SQLText s toSqlData (LDateTime t) = SQLText $ pack $ fmtTime sqlDateTimeFormat t@@ -219,7 +224,7 @@ toSqlData (LUUID x) = SQLBlob (toStrict $ toByteString x) fromSqlData :: SQLData -> SqlValue-fromSqlData (SQLInteger i) = SqlInt $ fromIntegral i+fromSqlData (SQLInteger i) = SqlInt64 $ fromIntegral i fromSqlData (SQLFloat f) = SqlFloat f fromSqlData (SQLText s) = SqlString s fromSqlData (SQLBlob b) = SqlBlob b