From 16004c2cf83c8161b0faa2a78eb8aa4b469a666e Mon Sep 17 00:00:00 2001 From: Finn Espen Gundersen Date: Fri, 25 Dec 2020 20:57:34 +0100 Subject: [PATCH] support createMany [] closes #627 --- IHP/SchemaCompiler.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/IHP/SchemaCompiler.hs b/IHP/SchemaCompiler.hs index 1ded89385..c4d66617b 100644 --- a/IHP/SchemaCompiler.hs +++ b/IHP/SchemaCompiler.hs @@ -378,6 +378,7 @@ compileCreate table@(CreateTable { name, columns }) = "create :: (?modelContext :: ModelContext) => " <> modelName <> " -> IO " <> modelName <> "\n" <> "create model = do\n" <> indent ("List.head <$> withDatabaseConnection \\databaseConnection -> Database.PostgreSQL.Simple.query databaseConnection \"INSERT INTO " <> name <> " (" <> columnNames <> ") VALUES (" <> values <> ") RETURNING *\" (" <> compileToRowValues bindings <> ")\n") + <> "createMany [] = pure []\n" <> "createMany models = do\n" <> indent ("withDatabaseConnection \\databaseConnection -> " <> createManyQueryFn <> " databaseConnection (Query $ \"INSERT INTO " <> name <> " (" <> columnNames <> ") VALUES \" <> (ByteString.intercalate \", \" (List.map (\\_ -> \"(" <> values <> ")\") models)) <> \" RETURNING *\") " <> createManyFieldValues <> "\n"