-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e16f43
commit 51c13dc
Showing
3 changed files
with
9 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
module PostgREST.Plan.Types | ||
( TypedField(..) | ||
, resolveField | ||
, resolveTableField | ||
|
||
) where | ||
|
||
import qualified Data.HashMap.Strict.InsOrd as HMI | ||
|
||
import PostgREST.ApiRequest.Types (Field, JsonPath) | ||
|
||
import PostgREST.SchemaCache.Identifiers (FieldName) | ||
import PostgREST.SchemaCache.Table (Column (..), Table (..)) | ||
|
||
import Protolude | ||
|
||
-- | A TypedField is a field with sufficient information to be read from JSON with `json_to_recordset`. | ||
data TypedField = TypedField | ||
{ tfFieldName :: FieldName | ||
, tfJsonPath :: JsonPath | ||
, tfIRType :: Text | ||
{ tfName :: FieldName | ||
, tfIRType :: Text -- ^ The initial type of the field, before any casting. | ||
} deriving (Eq) | ||
|
||
resolveField :: Field -> Text -> TypedField | ||
resolveField (fieldName, jsonPath) = TypedField fieldName jsonPath | ||
|
||
resolveTableField :: Table -> FieldName -> Maybe TypedField | ||
resolveTableField table fieldName = | ||
case HMI.lookup fieldName (tableColumns table) of | ||
Just column -> Just $ resolveField (colName column, []) (colNominalType column) | ||
Just column -> Just $ TypedField (colName column) (colNominalType column) | ||
Nothing -> Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters