mirror of
https://github.com/Airsequel/AirGQL.git
synced 2025-06-28 21:41:14 +02:00
Enable the foreign key pragma everywhere
This commit is contained in:
parent
be818d626c
commit
4fdbb30b5e
5 changed files with 8 additions and 5 deletions
|
@ -64,6 +64,7 @@ import AirGQL.Utils (
|
|||
getGraphiQLVersion,
|
||||
getSqliteBinaryVersion,
|
||||
getSqliteEmbeddedVersion,
|
||||
withRetryConn,
|
||||
)
|
||||
import Server.Server (platformApp)
|
||||
|
||||
|
@ -198,7 +199,7 @@ main = do
|
|||
putText versionSlug
|
||||
----------
|
||||
Serve{dbFilePath} -> do
|
||||
SS.withConnection dbFilePath $ \conn -> do
|
||||
withRetryConn dbFilePath $ \conn -> do
|
||||
P.when (dbFilePath == "") $
|
||||
P.die "ERROR: No database file path was specified"
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ sqlQueryPostHandler pragmaConf dbId sqlPost = do
|
|||
validationErrors <- liftIO $ case parseSql sqlPost.query of
|
||||
Left error -> pure [prettyError error]
|
||||
Right statement@(CreateTable{}) ->
|
||||
SS.withConnection (getMainDbPath dbId) $ \conn ->
|
||||
withRetryConn (getMainDbPath dbId) $ \conn ->
|
||||
lintTableCreationCode (Just conn) statement
|
||||
_ -> pure []
|
||||
|
||||
|
|
|
@ -358,4 +358,5 @@ withRetryConn :: FilePath -> (Connection -> IO a) -> IO a
|
|||
withRetryConn filePath action = do
|
||||
SS.withConnection filePath $ \conn -> do
|
||||
SS.execute_ conn "PRAGMA busy_timeout = 5000;" -- 5 seconds
|
||||
SS.execute_ conn "PRAGMA foreign_keys = True"
|
||||
action conn
|
||||
|
|
|
@ -180,7 +180,7 @@ testSuite = do
|
|||
results `shouldBe` ["hi world", "hi World", "HeLLo WorLd"]
|
||||
|
||||
it "loads all tables from database" $ do
|
||||
tables <- SS.withConnection dbPath $ \conn ->
|
||||
tables <- withRetryConn dbPath $ \conn ->
|
||||
getTables conn
|
||||
|
||||
shouldBe
|
||||
|
@ -217,7 +217,7 @@ testSuite = do
|
|||
|
||||
describe "getColumns" $ do
|
||||
it "loads all columns from users table" $ do
|
||||
tableColumns <- SS.withConnection dbPath $ \conn ->
|
||||
tableColumns <- withRetryConn dbPath $ \conn ->
|
||||
getColumns fixtureDbId conn "users"
|
||||
|
||||
let
|
||||
|
|
|
@ -32,6 +32,7 @@ import AirGQL.Types.SchemaConf (SchemaConf (accessMode), defaultSchemaConf)
|
|||
import AirGQL.Types.SqlQueryPostResult (
|
||||
SqlQueryPostResult (rows),
|
||||
)
|
||||
import AirGQL.Utils (withRetryConn)
|
||||
import Data.Text qualified as T
|
||||
import Database.SQLite.Simple (SQLData (SQLFloat, SQLInteger, SQLNull, SQLText))
|
||||
import Servant (runHandler)
|
||||
|
@ -193,7 +194,7 @@ main = void $ do
|
|||
|
||||
it "supports inserting empty records" $ do
|
||||
let testDbPath = testRoot </> "empty-record-insertion.db"
|
||||
SS.withConnection testDbPath $ \conn -> do
|
||||
withRetryConn testDbPath $ \conn -> do
|
||||
SS.execute_
|
||||
conn
|
||||
[sql|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue