Skip to content

Commit 4eff4b1

Browse files
committed
Fixes #13
1 parent 5e82c78 commit 4eff4b1

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

src/Droplet/Language/Internal/Syntax.purs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ module Droplet.Language.Internal.Syntax
4141
, class ValidColumnNames
4242
, class IncludeColumn
4343
, class ColumnCannotBeSet
44+
, class MultipleInsert
45+
, class SingleInsert
4446
, class OnlyAggregations
47+
, class ConsistentArity
4548
, class LimitedResults
4649
, class ToAdd
4750
, class ColumnNames
@@ -780,7 +783,7 @@ instance ToStringAgg (Path table name) (OrderBy (Path alias fd) String) columns
780783

781784
------------------------LIMIT---------------------------
782785

783-
data Limit (n :: Int) rest = Limit rest
786+
data Limit (n Int) rest = Limit rest
784787

785788
class ToLimit (qType)
786789

@@ -806,7 +809,6 @@ instance ToLimit (Select s projection (From fr fields (Where cd (GroupBy fg (Ord
806809
limit n q sql. ToLimit q Resume q (Limit n E) sql Proxy n q sql
807810
limit _ q = resume q $ Limit E
808811

809-
810812
------------------------OFFSET---------------------------
811813

812814
data Offset rest = Offset Int rest
@@ -1007,7 +1009,7 @@ data Values fieldValues rest = Values fieldValues rest
10071009

10081010
data DefaultValues = DefaultValues
10091011

1010-
class InsertValues (fieldsRow Type) (fieldNamesType) (tType)
1012+
class InsertValues (fieldsRow Type) (namesType) (tType)
10111013

10121014
-- | Multiple values, single column
10131015
instance InsertValues fields (Proxy name) u InsertValues fields (Proxy name) (Array u)
@@ -1045,8 +1047,45 @@ else instance
10451047
)
10461048
IsDefault t name
10471049

1048-
values tableName fields fieldNames fieldValues. InsertValues fields fieldNames fieldValues fieldValues Insert (Into tableName fields fieldNames E) Insert (Into tableName fields fieldNames (Values fieldValues E))
1049-
values fieldValues (Insert (Into fieldNames _)) = Insert <<< Into fieldNames $ Values fieldValues E
1050+
-- | Makes sure single and multiple insert syntax is not mixed
1051+
class ConsistentArity (valuesType)
1052+
1053+
-- | Multiple values, single column
1054+
instance ConsistentArity (Array t)
1055+
1056+
-- | Multiple values, many columns
1057+
else instance MultipleInsert u ConsistentArity (Array t /\ u)
1058+
1059+
-- | Column list
1060+
else instance SingleInsert u ConsistentArity (t /\ u)
1061+
1062+
-- | Single value
1063+
else instance ConsistentArity t
1064+
1065+
class MultipleInsert (tType)
1066+
1067+
instance MultipleInsert (Array t)
1068+
1069+
else instance MultipleInsert t MultipleInsert (Array t /\ u)
1070+
1071+
else instance Fail (Text "Multiple INSERT value list must be array") MultipleInsert u
1072+
1073+
class SingleInsert (tType)
1074+
1075+
instance SingleInsert t SingleInsert (t /\ u)
1076+
1077+
else instance Fail (Text "Single INSERT value list must not be array") SingleInsert (Array t)
1078+
1079+
else instance SingleInsert t
1080+
1081+
values
1082+
tableName fields names fieldValues.
1083+
ConsistentArity fieldValues
1084+
InsertValues fields names fieldValues
1085+
fieldValues
1086+
Insert (Into tableName fields names E)
1087+
Insert (Into tableName fields names (Values fieldValues E))
1088+
values fieldValues (Insert (Into names _)) = Insert <<< Into names $ Values fieldValues E
10501089

10511090
defaultValues DefaultValues
10521091
defaultValues = DefaultValues

0 commit comments

Comments
 (0)