Effect CommunityEC
Effect Community3y ago
4 replies
joe.esteves

Using `sqlfx` to Insert Multiple Rows at Once

Hello, I'm trying to use sqlfx to get familiar with it. I want to make a insert statement to insert multiple rows (task) at once, but couln't succeed yet. If someone know what is the correct way to achieve that I'll really appretiate the help. Here is what I got so far

const createFx = (tasks: Array<Record<string, unknown>>) =>
  pipe(
    bindings(tasks),
    Effect.flatMap(
      ({ decodedTasks, sql }) =>
        sql<
        Schema.Schema.To<typeof Task>
        >`INSERT INTO tasks (description, person_id) VALUES '${decodedTasks
          .map((t) => sql`(${t.description}, 1)`)
          .join(',')}' RETURNING *;`
    )
  )


this is the error I'm getting error: {"message":"syntax error at or near \"'$1'\"","error":{},"_tag":"SqlError"}

thanks
Was this page helpful?