Skip to content

Instantly share code, notes, and snippets.

View avdgaag's full-sized avatar

Arjan van der Gaag avdgaag

View GitHub Profile

Keybase proof

I hereby claim:

  • I am avdgaag on github.
  • I am avdgaag (https://keybase.io/avdgaag) on keybase.
  • I have a public key whose fingerprint is 4F42 6A06 0AD7 FB17 65C7 F164 7109 F6F2 67B5 C31C

To claim this, I am signing this object:

import Html.App as App
import Html exposing (..)
import Html.Attributes exposing (..)
import Http
import Task
import Json.Decode as Json exposing ((:=))
-- MODEL
type alias Model =
@avdgaag
avdgaag / stream_csv.ex
Created July 13, 2017 09:28
Streaming CSV straight out of the database to the client using Elixir, Phoenix, Ecto and PostgreSQL.
def index(conn, _params) do
conn = conn
|> put_resp_content_type("text/csv")
|> put_resp_header("content-disposition", "attachment; filename=export.csv")
|> send_cunked(200)
Repo.transaction fn ->
Ecto.Adapters.SQL.stream(Repo, "COPY expensive_report TO STDOUT CSV HEADER")
|> Stream.map(&(chunk(conn, &1.rows)))
|> Stream.run