Skip to content

Commit

Permalink
Added support for Double/Float64 in DataSync. Fixes #1298
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Jan 13, 2022
1 parent 663324a commit 3969ab9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions IHP/DataSync/DynamicQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data Field = Field { fieldName :: Text, fieldValue :: DynamicValue }

data DynamicValue
= IntValue !Int
| DoubleValue !Double
| TextValue !Text
| BoolValue !Bool
| UUIDValue !UUID
Expand Down Expand Up @@ -78,6 +79,7 @@ instance {-# OVERLAPS #-} ToJSON [Field] where
toJSON fields = object (map (\Field { fieldName, fieldValue } -> (cs fieldName) .= (fieldValueToJSON fieldValue)) fields)
where
fieldValueToJSON (IntValue value) = toJSON value
fieldValueToJSON (DoubleValue value) = toJSON value
fieldValueToJSON (TextValue value) = toJSON value
fieldValueToJSON (BoolValue value) = toJSON value
fieldValueToJSON (UUIDValue value) = toJSON value
Expand All @@ -97,6 +99,7 @@ instance PG.FromField Field where
<|> (TextValue <$> PG.fromField field fieldValue')
<|> (BoolValue <$> PG.fromField field fieldValue')
<|> (UUIDValue <$> PG.fromField field fieldValue')
<|> (DoubleValue <$> PG.fromField field fieldValue')
<|> (DateTimeValue <$> PG.fromField field fieldValue')
<|> (PG.fromField @PG.Null field fieldValue' >> pure IHP.DataSync.DynamicQuery.Null)
<|> fromFieldCustomEnum field fieldValue'
Expand Down
1 change: 1 addition & 0 deletions IHP/DataSync/DynamicQueryCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ compileCondition (InfixOperatorExpression a operator b) = ("(" <> queryA <> ") "
compileCondition (LiteralExpression literal) = ("?", [toValue literal])
where
toValue (IntValue int) = PG.toField int
toValue (DoubleValue double) = PG.toField double
toValue (TextValue text) = PG.toField text
toValue (BoolValue bool) = PG.toField bool
toValue (UUIDValue uuid) = PG.toField uuid
Expand Down
2 changes: 1 addition & 1 deletion lib/IHP/DataSync/ihp-querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function jsValueToDynamicValue(value) {
if (typeof value === "string") {
return { tag: 'TextValue', contents: value };
} else if (typeof value === "number") {
return { tag: 'IntValue', contents: value };
return { tag: Number.isInteger(value) ? 'IntValue' : 'DoubleValue', contents: value };
} else if (typeof value === "boolean") {
return { tag: 'BoolValue', contents: value };
} else if (value === null || value === undefined) {
Expand Down

0 comments on commit 3969ab9

Please sign in to comment.