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