mirror of
https://github.com/Airsequel/AirGQL.git
synced 2025-08-21 22:06:57 +03:00
Implement main reference following mechanism on the backend
This commit is contained in:
parent
5372e9253c
commit
cb0127ddd1
1 changed files with 49 additions and 44 deletions
|
@ -9,6 +9,8 @@ module AirGQL.Lib (
|
||||||
AccessMode (..),
|
AccessMode (..),
|
||||||
ColumnEntry (..),
|
ColumnEntry (..),
|
||||||
GqlTypeName (..),
|
GqlTypeName (..),
|
||||||
|
getEnrichedTable,
|
||||||
|
getColumnsFromParsedTableEntry,
|
||||||
getColumns,
|
getColumns,
|
||||||
getRowidColumnName,
|
getRowidColumnName,
|
||||||
getTables,
|
getTables,
|
||||||
|
@ -869,51 +871,54 @@ getColumnsFromParsedTableEntry connection tableEntry = do
|
||||||
pure $ rowidColumns <> entries
|
pure $ rowidColumns <> entries
|
||||||
|
|
||||||
|
|
||||||
|
getEnrichedTable :: Text -> Connection -> Text -> IO TableEntry
|
||||||
|
getEnrichedTable dbId connection tableName = do
|
||||||
|
tables :: [TableEntryRaw] <-
|
||||||
|
SS.query
|
||||||
|
connection
|
||||||
|
[SS.sql|
|
||||||
|
SELECT name, tbl_name, type, rootpage, sql
|
||||||
|
FROM sqlite_master
|
||||||
|
WHERE name == ?
|
||||||
|
|]
|
||||||
|
[tableName]
|
||||||
|
|
||||||
|
table <- case P.head tables of
|
||||||
|
Just table -> pure table
|
||||||
|
Nothing ->
|
||||||
|
fail $
|
||||||
|
P.fold
|
||||||
|
[ "Could not find table info for table "
|
||||||
|
, T.unpack tableName
|
||||||
|
, " of db "
|
||||||
|
, T.unpack dbId
|
||||||
|
]
|
||||||
|
|
||||||
|
enrichmentResultEither <- enrichTableEntry connection table
|
||||||
|
case enrichmentResultEither of
|
||||||
|
Right result -> pure result
|
||||||
|
Left err ->
|
||||||
|
fail $
|
||||||
|
P.fold
|
||||||
|
[ "An error occurred while parsing table "
|
||||||
|
, T.unpack tableName
|
||||||
|
, " of db "
|
||||||
|
, T.unpack dbId
|
||||||
|
, ": "
|
||||||
|
, T.unpack err
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
getColumns :: Text -> Connection -> Text -> IO [ColumnEntry]
|
getColumns :: Text -> Connection -> Text -> IO [ColumnEntry]
|
||||||
getColumns dbId connection tableName =
|
getColumns dbId conn tableName =
|
||||||
let
|
let columns = do
|
||||||
columns = do
|
enrichingResult <- getEnrichedTable dbId conn tableName
|
||||||
tables :: [TableEntryRaw] <-
|
getColumnsFromParsedTableEntry conn enrichingResult
|
||||||
SS.query
|
in catchAll
|
||||||
connection
|
columns
|
||||||
[SS.sql|
|
$ \err -> do
|
||||||
SELECT name, tbl_name, type, rootpage, sql
|
P.putErrText $ P.show err
|
||||||
FROM sqlite_master
|
pure []
|
||||||
WHERE name == ?
|
|
||||||
|]
|
|
||||||
[tableName]
|
|
||||||
|
|
||||||
table <- case P.head tables of
|
|
||||||
Just table -> pure table
|
|
||||||
Nothing ->
|
|
||||||
fail $
|
|
||||||
P.fold
|
|
||||||
[ "Could not find table info for table "
|
|
||||||
, T.unpack tableName
|
|
||||||
, " of db "
|
|
||||||
, T.unpack dbId
|
|
||||||
]
|
|
||||||
|
|
||||||
enrichmentResultEither <- enrichTableEntry connection table
|
|
||||||
enrichingResult <- case enrichmentResultEither of
|
|
||||||
Right result -> pure result
|
|
||||||
Left err ->
|
|
||||||
fail $
|
|
||||||
P.fold
|
|
||||||
[ "An error occurred while parsing table "
|
|
||||||
, T.unpack tableName
|
|
||||||
, " of db "
|
|
||||||
, T.unpack dbId
|
|
||||||
, ": "
|
|
||||||
, T.unpack err
|
|
||||||
]
|
|
||||||
getColumnsFromParsedTableEntry connection enrichingResult
|
|
||||||
in
|
|
||||||
catchAll
|
|
||||||
columns
|
|
||||||
$ \err -> do
|
|
||||||
P.putErrText $ P.show err
|
|
||||||
pure []
|
|
||||||
|
|
||||||
|
|
||||||
newtype SelectOptions = SelectOptions {unSelectOptions :: [Text]}
|
newtype SelectOptions = SelectOptions {unSelectOptions :: [Text]}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue