A ready-made database module that reads config :moebius, connection: [...]. Add it to
your supervision tree, or define your own with use Moebius.Database.
Summary
Functions
Bulk loads rows into a table with Postgres's COPY protocol, the fastest way to write
many rows. Returns {:ok, count} or {:error, message}; if any row fails, none are
written.
Asks Postgres how it will run a query, and returns the plan as text.
The pool's size and how much of it is in use.
Rolls back the current transaction, which then returns {:error, value}.
Starts this database's connection pool. See Moebius.Database for the options.
Streams the rows of a query or document query through a server-side cursor, so large results never sit in memory at once. Read it in the process that created it.
Runs fun in a transaction and returns what it returns.
Functions
See Moebius.Db.run/1.
Bulk loads rows into a table with Postgres's COPY protocol, the fastest way to write
many rows. Returns {:ok, count} or {:error, message}; if any row fails, none are
written.
rows is any Enumerable of keyword lists or maps, including a lazy Stream, which is
sent in chunks so memory stays flat however many rows there are. The columns are the
keys of the first row, unless you pass :columns.
:columns- the columns to fill, in order.:chunk- rows sent per message to the server (default 5,000).
"events.csv"
|> File.stream!()
|> CSV.decode!(headers: true)
|> Stream.map(&%{name: &1["name"], at: &1["at"]})
|> MyApp.Db.copy(:events)
Asks Postgres how it will run a query, and returns the plan as text.
:analyze- also run the query and report real timings and row counts. The query runs inside a transaction that is rolled back, so writes are not kept.
See Moebius.Db.first/1.
The pool's size and how much of it is in use.
Rolls back the current transaction, which then returns {:error, value}.
Starts this database's connection pool. See Moebius.Database for the options.
Streams the rows of a query or document query through a server-side cursor, so large results never sit in memory at once. Read it in the process that created it.
:chunk- rows fetched per round-trip (default 500).
db(:events) |> sort(:id) |> MyApp.Db.stream() |> Stream.each(&handle/1) |> Stream.run()
Runs fun in a transaction and returns what it returns.
If a statement inside fails, or fun calls rollback/1, the transaction is rolled back
and this returns {:error, reason}. If fun raises anything else, the transaction is
rolled back and the exception is re-raised. A transaction inside a transaction becomes a
savepoint, so it can fail without taking the outer one down.