From 3969ab962741be684a9769dbf7ea109406b0410b Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Thu, 13 Jan 2022 22:40:14 +0100 Subject: [PATCH] Added support for Double/Float64 in DataSync. Fixes #1298 --- IHP/DataSync/DynamicQuery.hs | 3 +++ IHP/DataSync/DynamicQueryCompiler.hs | 1 + lib/IHP/DataSync/ihp-querybuilder.js | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/IHP/DataSync/DynamicQuery.hs b/IHP/DataSync/DynamicQuery.hs index f8783a22c..a29ff445e 100644 --- a/IHP/DataSync/DynamicQuery.hs +++ b/IHP/DataSync/DynamicQuery.hs @@ -21,6 +21,7 @@ data Field = Field { fieldName :: Text, fieldValue :: DynamicValue } data DynamicValue = IntValue !Int + | DoubleValue !Double | TextValue !Text | BoolValue !Bool | UUIDValue !UUID @@ -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 @@ -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' diff --git a/IHP/DataSync/DynamicQueryCompiler.hs b/IHP/DataSync/DynamicQueryCompiler.hs index 51db280c4..1512bc154 100644 --- a/IHP/DataSync/DynamicQueryCompiler.hs +++ b/IHP/DataSync/DynamicQueryCompiler.hs @@ -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 diff --git a/lib/IHP/DataSync/ihp-querybuilder.js b/lib/IHP/DataSync/ihp-querybuilder.js index 547a20fb7..c6c832e8e 100644 --- a/lib/IHP/DataSync/ihp-querybuilder.js +++ b/lib/IHP/DataSync/ihp-querybuilder.js @@ -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) {