builtins.ex (4231B)
1 defmodule Postgrex.Interval do 2 @moduledoc """ 3 Struct for PostgreSQL `interval`. 4 5 ## Fields 6 7 * `months` 8 * `days` 9 * `secs` 10 * `microsecs` 11 12 """ 13 14 @type t :: %__MODULE__{months: integer, days: integer, secs: integer, microsecs: integer} 15 16 defstruct months: 0, days: 0, secs: 0, microsecs: 0 17 18 def compare( 19 %__MODULE__{months: m1, days: d1, secs: s1, microsecs: ms1}, 20 %__MODULE__{months: m2, days: d2, secs: s2, microsecs: ms2} 21 ) do 22 t1 = {m1, d1, s1, ms1} 23 t2 = {m2, d2, s2, ms2} 24 25 cond do 26 t1 > t2 -> :gt 27 t1 < t2 -> :lt 28 true -> :eq 29 end 30 end 31 32 def to_string(%__MODULE__{months: months, days: days, secs: secs, microsecs: microsecs}) do 33 optional_interval(months, :month) <> 34 optional_interval(days, :day) <> 35 Integer.to_string(secs) <> 36 optional_microsecs(microsecs) <> 37 " seconds" 38 end 39 40 defp optional_interval(0, _), do: "" 41 defp optional_interval(1, key), do: "1 #{key}, " 42 defp optional_interval(n, key), do: "#{n} #{key}s, " 43 44 defp optional_microsecs(0), 45 do: "" 46 47 defp optional_microsecs(ms), 48 do: "." <> (ms |> Integer.to_string() |> String.pad_leading(6, "0")) 49 end 50 51 defmodule Postgrex.Range do 52 @moduledoc """ 53 Struct for PostgreSQL `range`. 54 55 ## Fields 56 57 * `lower` 58 * `upper` 59 * `lower_inclusive` 60 * `upper_inclusive` 61 62 """ 63 64 @type t :: %__MODULE__{ 65 lower: term | :empty | :unbound, 66 upper: term | :empty | :unbound, 67 lower_inclusive: boolean, 68 upper_inclusive: boolean 69 } 70 71 defstruct lower: nil, upper: nil, lower_inclusive: true, upper_inclusive: true 72 end 73 74 defmodule Postgrex.INET do 75 @moduledoc """ 76 Struct for PostgreSQL `inet` / `cidr`. 77 78 ## Fields 79 80 * `address` 81 * `netmask` 82 83 """ 84 85 @type t :: %__MODULE__{address: :inet.ip_address(), netmask: nil | 0..128} 86 87 defstruct address: nil, netmask: nil 88 end 89 90 defmodule Postgrex.MACADDR do 91 @moduledoc """ 92 Struct for PostgreSQL `macaddr`. 93 94 ## Fields 95 96 * `address` 97 98 """ 99 100 @type macaddr :: {0..255, 0..255, 0..255, 0..255, 0..255, 0..255} 101 102 @type t :: %__MODULE__{address: macaddr} 103 104 defstruct address: nil 105 end 106 107 defmodule Postgrex.Point do 108 @moduledoc """ 109 Struct for PostgreSQL `point`. 110 111 ## Fields 112 113 * `x` 114 * `y` 115 116 """ 117 118 @type t :: %__MODULE__{x: float, y: float} 119 120 defstruct x: nil, y: nil 121 end 122 123 defmodule Postgrex.Polygon do 124 @moduledoc """ 125 Struct for PostgreSQL `polygon`. 126 127 ## Fields 128 129 * `vertices` 130 131 """ 132 133 @type t :: %__MODULE__{vertices: [Postgrex.Point.t()]} 134 135 defstruct vertices: nil 136 end 137 138 defmodule Postgrex.Line do 139 @moduledoc """ 140 Struct for PostgreSQL `line`. 141 142 Note, lines are stored in PostgreSQL in the form `{a, b, c}`, which 143 parameterizes a line as `a*x + b*y + c = 0`. 144 145 ## Fields 146 147 * `a` 148 * `b` 149 * `c` 150 151 """ 152 153 @type t :: %__MODULE__{a: float, b: float, c: float} 154 155 defstruct a: nil, b: nil, c: nil 156 end 157 158 defmodule Postgrex.LineSegment do 159 @moduledoc """ 160 Struct for PostgreSQL `lseg`. 161 162 ## Fields 163 164 * `point1` 165 * `point2` 166 167 """ 168 169 @type t :: %__MODULE__{point1: Postgrex.Point.t(), point2: Postgrex.Point.t()} 170 171 defstruct point1: nil, point2: nil 172 end 173 174 defmodule Postgrex.Box do 175 @moduledoc """ 176 Struct for PostgreSQL `box`. 177 178 ## Fields 179 180 * `upper_right` 181 * `bottom_left` 182 183 """ 184 185 @type t :: %__MODULE__{ 186 upper_right: Postgrex.Point.t(), 187 bottom_left: Postgrex.Point.t() 188 } 189 190 defstruct upper_right: nil, bottom_left: nil 191 end 192 193 defmodule Postgrex.Path do 194 @moduledoc """ 195 Struct for PostgreSQL `path`. 196 197 ## Fields 198 199 * `open` 200 * `points` 201 202 """ 203 204 @type t :: %__MODULE__{points: [Postgrex.Point.t()], open: boolean} 205 206 defstruct points: nil, open: nil 207 end 208 209 defmodule Postgrex.Circle do 210 @moduledoc """ 211 Struct for PostgreSQL `circle`. 212 213 ## Fields 214 215 * `center` 216 * `radius` 217 218 """ 219 @type t :: %__MODULE__{center: Postgrex.Point.t(), radius: number} 220 221 defstruct center: nil, radius: nil 222 end 223 224 defmodule Postgrex.Lexeme do 225 @moduledoc """ 226 Struct for PostgreSQL `lexeme`. 227 228 ## Fields 229 230 * `word` 231 * `positions` 232 233 """ 234 235 @type t :: %__MODULE__{word: String.t(), positions: [{pos_integer, :A | :B | :C | nil}]} 236 237 defstruct word: nil, positions: nil 238 end