Packages
postgrex
0.19.0
1.0.0-rc.1
retired
1.0.0-rc.0
retired
0.22.3
0.22.2
0.22.1
0.22.0
0.21.1
0.21.0
0.20.0
0.19.3
0.19.2
0.19.1
0.19.0
0.18.0
0.17.5
0.17.4
0.17.3
0.17.2
0.17.1
0.17.0
0.16.5
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.13
0.15.12
0.15.11
0.15.10
0.15.9
0.15.8
0.15.7
0.15.6
0.15.5
0.15.4
0.15.3
0.15.2
0.15.1
0.15.0
0.14.3
0.14.2
0.14.1
0.14.0
0.14.0-rc.1
0.14.0-rc.0
0.13.5
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.13.0-rc.0
0.12.2
0.12.1
0.12.0
0.11.2
0.11.1
0.11.0
0.10.0
0.9.1
0.9.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.0
0.6.0
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.2
PostgreSQL driver for Elixir
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/postgrex/builtins.ex
defmodule Postgrex.Interval do
@moduledoc """
Struct for PostgreSQL `interval`.
## Fields
* `months`
* `days`
* `secs`
* `microsecs`
"""
@type t :: %__MODULE__{months: integer, days: integer, secs: integer, microsecs: integer}
defstruct months: 0, days: 0, secs: 0, microsecs: 0
def compare(
%__MODULE__{months: m1, days: d1, secs: s1, microsecs: ms1},
%__MODULE__{months: m2, days: d2, secs: s2, microsecs: ms2}
) do
t1 = {m1, d1, s1, ms1}
t2 = {m2, d2, s2, ms2}
cond do
t1 > t2 -> :gt
t1 < t2 -> :lt
true -> :eq
end
end
def to_string(%__MODULE__{months: months, days: days, secs: secs, microsecs: microsecs}) do
optional_interval(months, :month) <>
optional_interval(days, :day) <>
Integer.to_string(secs) <>
optional_microsecs(microsecs) <>
" seconds"
end
defp optional_interval(0, _), do: ""
defp optional_interval(1, key), do: "1 #{key}, "
defp optional_interval(n, key), do: "#{n} #{key}s, "
defp optional_microsecs(0),
do: ""
defp optional_microsecs(ms),
do: "." <> (ms |> Integer.to_string() |> String.pad_leading(6, "0"))
end
defmodule Postgrex.Range do
@moduledoc """
Struct for PostgreSQL `range`.
Note that PostgreSQL itself does not return ranges exactly as stored:
`SELECT '(1,5)'::int4range` returns `[2,5)`, which is equivalent in terms
of the values included in the range ([PostgreSQL docs](https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-IO)).
When selecting data, this struct simply reflects what PostgreSQL returns.
## Fields
* `lower`
* `upper`
* `lower_inclusive`
* `upper_inclusive`
"""
@type t :: %__MODULE__{
lower: term | :empty | :unbound,
upper: term | :empty | :unbound,
lower_inclusive: boolean,
upper_inclusive: boolean
}
defstruct lower: nil, upper: nil, lower_inclusive: true, upper_inclusive: true
end
defmodule Postgrex.Multirange do
@moduledoc """
Struct for PostgreSQL `multirange`.
## Fields
* `ranges`
"""
@type t :: %__MODULE__{ranges: [Postgrex.Range.t()]}
defstruct ranges: nil
end
defmodule Postgrex.INET do
@moduledoc """
Struct for PostgreSQL `inet` / `cidr`.
## Fields
* `address`
* `netmask`
"""
@type t :: %__MODULE__{address: :inet.ip_address(), netmask: nil | 0..128}
defstruct address: nil, netmask: nil
end
defmodule Postgrex.MACADDR do
@moduledoc """
Struct for PostgreSQL `macaddr`.
## Fields
* `address`
"""
@type macaddr :: {0..255, 0..255, 0..255, 0..255, 0..255, 0..255}
@type t :: %__MODULE__{address: macaddr}
defstruct address: nil
end
defmodule Postgrex.Point do
@moduledoc """
Struct for PostgreSQL `point`.
## Fields
* `x`
* `y`
"""
@type t :: %__MODULE__{x: float, y: float}
defstruct x: nil, y: nil
end
defmodule Postgrex.Polygon do
@moduledoc """
Struct for PostgreSQL `polygon`.
## Fields
* `vertices`
"""
@type t :: %__MODULE__{vertices: [Postgrex.Point.t()]}
defstruct vertices: nil
end
defmodule Postgrex.Line do
@moduledoc """
Struct for PostgreSQL `line`.
Note, lines are stored in PostgreSQL in the form `{a, b, c}`, which
parameterizes a line as `a*x + b*y + c = 0`.
## Fields
* `a`
* `b`
* `c`
"""
@type t :: %__MODULE__{a: float, b: float, c: float}
defstruct a: nil, b: nil, c: nil
end
defmodule Postgrex.LineSegment do
@moduledoc """
Struct for PostgreSQL `lseg`.
## Fields
* `point1`
* `point2`
"""
@type t :: %__MODULE__{point1: Postgrex.Point.t(), point2: Postgrex.Point.t()}
defstruct point1: nil, point2: nil
end
defmodule Postgrex.Box do
@moduledoc """
Struct for PostgreSQL `box`.
## Fields
* `upper_right`
* `bottom_left`
"""
@type t :: %__MODULE__{
upper_right: Postgrex.Point.t(),
bottom_left: Postgrex.Point.t()
}
defstruct upper_right: nil, bottom_left: nil
end
defmodule Postgrex.Path do
@moduledoc """
Struct for PostgreSQL `path`.
## Fields
* `open`
* `points`
"""
@type t :: %__MODULE__{points: [Postgrex.Point.t()], open: boolean}
defstruct points: nil, open: nil
end
defmodule Postgrex.Circle do
@moduledoc """
Struct for PostgreSQL `circle`.
## Fields
* `center`
* `radius`
"""
@type t :: %__MODULE__{center: Postgrex.Point.t(), radius: number}
defstruct center: nil, radius: nil
end
defmodule Postgrex.Lexeme do
@moduledoc """
Struct for PostgreSQL `lexeme`.
## Fields
* `word`
* `positions`
"""
@type t :: %__MODULE__{word: String.t(), positions: [{pos_integer, :A | :B | :C | nil}]}
defstruct word: nil, positions: nil
end