This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Postgrex.Extensions.Numeric do | |
@moduledoc false | |
import Postgrex.BinaryUtils, warn: false | |
use Postgrex.BinaryExtension, send: "numeric_send" | |
def init(opts) do | |
Keyword.get(opts, :numeric, Postgrex.Extensions.Numeric.Decimal) | |
end | |
def encode(handler) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule :posterize_xt_date do | |
@moduledoc false | |
@behaviour Postgrex.Extension | |
import Postgrex.BinaryUtils, warn: false | |
use Postgrex.BinaryExtension, [send: "date_send"] | |
@pg_epoch :calendar.date_to_gregorian_days({ 2000, 1, 1 }) | |
@max_year 5874897 | |
@min_year -4713 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule :posterize_xt_timestamp do | |
@moduledoc false | |
@behaviour Postgrex.Extension | |
import Postgrex.BinaryUtils, warn: false | |
use Postgrex.BinaryExtension, [send: "timestamp_send"] | |
@unix_epoch :calendar.datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}) | |
@gs_epoch :calendar.datetime_to_gregorian_seconds({{2000, 1, 1}, {0, 0, 0}}) | |
@adjustment :erlang.convert_time_unit(@gs_epoch - @unix_epoch, :seconds, :microsecond) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reload_config(path_to_config) do | |
config = File.read!(path_to_config) |> Poison.decode! | |
Application.put_env(AppA, KeyA, config["key_a"]) | |
Application.put_env(AppB, KeyB, config["key_b"]) | |
Application.stop(AppA) | |
Application.stop(AppB) | |
Application.start(AppA) | |
Application.start(AppB) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
talentdeficit=# SELECT '2016-12-31T23:59:60Z'::timestamp; | |
timestamp | |
--------------------- | |
2017-01-01 00:00:00 | |
(1 row) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres=# SELECT TIMESTAMP 'January 1, 99 AD' > TIMESTAMP 'January 1, 100 AD' | |
?column? | |
---------- | |
t | |
(1 row) | |
postgres=# SELECT TIMESTAMP 'January 1, 2001 AD' = TIMESTAMP 'January 1, 1 AD' ; | |
?column? | |
---------- | |
t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule :posterize_xt_time do | |
@moduledoc false | |
@behaviour Postgrex.Extension | |
import Postgrex.BinaryUtils, warn: false | |
def init(opts) do | |
case Keyword.get(opts, :units) do | |
nil -> :native | |
units when is_atom(units) -> units | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= for {name, info} <- context[:shapes] do %>shape(<%= name %>) -> | |
<%= if info[:type] == <<"list">> %> | |
ok; | |
<% else %> | |
ok; | |
<% end %> | |
<% end %>shape(_) -> erlang:error(badarg). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(5)> dates = [DateTime.from_unix!(100000000), DateTime.from_unix!(100000)] [%DateTime{calendar: Calendar.ISO, day: 3, hour: 9, microsecond: {0, 0}, | |
minute: 46, month: 3, second: 40, std_offset: 0, time_zone: "Etc/UTC", | |
utc_offset: 0, year: 1973, zone_abbr: "UTC"}, | |
%DateTime{calendar: Calendar.ISO, day: 2, hour: 3, microsecond: {0, 0}, | |
minute: 46, month: 1, second: 40, std_offset: 0, time_zone: "Etc/UTC", | |
utc_offset: 0, year: 1970, zone_abbr: "UTC"}] | |
iex(6)> Enum.sort(dates) | |
[%DateTime{calendar: Calendar.ISO, day: 2, hour: 3, microsecond: {0, 0}, | |
minute: 46, month: 1, second: 40, std_offset: 0, time_zone: "Etc/UTC", | |
utc_offset: 0, year: 1970, zone_abbr: "UTC"}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# :for defaults to self() | |
{ :ok, ref } = Postgrex.aquery(conn, "SELECT user_id, text FROM comments", [{ :for, pid }]) | |
# some gen_server (@pid) | |
handle_info({ :postgrex_reply, ref, { :ok, %Postgrex.Result{..} } }, state) -> | |
... | |
end | |
handle_info({ :postgrex_reply, ref, { :error, %Postgrex.Error{..} } }, state) -> | |
... | |
end |