postgrex 0.8.0

PostgreSQL driver for Elixir.

Homepage: http://hexdocs.pm/postgrex/

Platform: Hex

Language: Elixir

License: Apache-2.0

Repository: https://github.com/ericmj/postgrex

View on registry: https://hex.pm/packages/postgrex/

Documentation: http://hexdocs.pm/postgrex/0.8.0


Postgrex

Build Status

PostgreSQL driver for Elixir.

Documentation: http://hexdocs.pm/postgrex/

Usage

Add Postgrex as a dependency in your mix.exs file.

def deps do
 [{:postgrex, "~> 0.8"} ]
end

After you are done, run mix deps.get in your shell to fetch and compile Postgrex. Start an interactive Elixir shell with iex -S mix.

iex> {:ok, pid} = Postgrex.Connection.start_link(hostname: "localhost", username: "postgres", password: "postgres", database: "postgres")
{:ok, #PID<0.69.0>}
iex> Postgrex.Connection.query!(pid, "SELECT user_id, text FROM comments", [])
%Postgrex.Result{command: :select, empty?: false, columns: ["user_id", "text"], rows: [{3,"hey"},{4,"there"}], size: 2}}
iex> Postgrex.Connection.query!(pid, "INSERT INTO comments (user_id, text) VALUES (10, 'heya')", [])
%Postgrex.Result{command: :insert, columns: nil, rows: nil, num_rows: 1}}

Features

  • Automatic decoding and encoding of Elixir values to and from PostgreSQL's binary format
  • User defined extensions for encoding and decoding any PostgresSQL type
  • Supports PostgreSQL 8.4, 9.0, 9.1, 9.2, 9.3, and 9.4

Data representation

PostgreSQL Elixir
---------- ------
NULL nil
bool true | false
char "é"
int 42
float 42.0
text "eric"
bytea <<42>>
numeric #Decimal<42.0> *
date %Postgrex.Date{year: 2013, month: 10, day: 12}
time %Postgrex.Time{hour: 0, min: 37, sec: 14, msec: 0}
timestamp(tz) %Postgrex.Timestamp{year: 2013 month: 10, day: 12, hour: 0, min: 37, sec: 14, msec: 0}
interval %Postgrex.Interval{months: 14, days: 40, secs: 10920}
array [1, 2, 3]
composite type {42, "title", "content"}
range %Postgrex.Range{lower: 1, upper: 5}
uuid <<160,238,188,153,156,11,78,248,187,109,107,185,189,56,10,17>>

* Decimal

Extensions

Extensions are used to extend Postgrex' built-in type encoding/decoding.

Below is an example of an extension that supports encoding/decoding Elixir maps to the Postgres' JSON type.

defmodule Extensions.JSON do
 alias Postgrex.TypeInfo
 @behaviour Postgrex.Extension
 def init(_parameters, opts),
 do: Keyword.fetch!(opts, :library)
 def matching(_library),
 do: [type: "json", type: "jsonb"]
 def format(_library),
 do: :binary
 def encode(%TypeInfo{type: "json"}, map, _state, library),
 do: library.encode!(map)
 def encode(%TypeInfo{type: "jsonb"}, map, _state, library),
 do: <<1, library.encode!(map)::binary>>
 def decode(%TypeInfo{type: "json"}, json, _state, library),
 do: library.decode!(json)
 def decode(%TypeInfo{type: "jsonb"}, <<1, json::binary>>, _state, library),
 do: library.decode!(json)
end
Postgrex.Connection.start_link(extensions: [{Extensions.JSON, library: Poison}], ...)

Contributing

To contribute you need to compile Postgrex from source and test it:

$ git clone https://github.com/ericmj/postgrex.git
$ cd postgrex
$ mix test

The tests requires some modifications to your hba file. The path to it can be found by running $ psql -U postgres -c "SHOW hba_file" in your shell. Put the following above all other configurations (so that they override):

host all postgrex_md5_pw 127.0.0.1/32 md5
host all postgrex_cleartext_pw 127.0.0.1/32 password

The server needs to be restarted for the changes to take effect. Additionally you need to setup a Postgres user with the same username as the local user and give it trust or ident in your hba file. Or you can export $PGUSER and $PGPASS before running tests.

License

Copyright 2013 Eric Meadows-Jönsson

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

веселые картинки развлекательные гифки интресные факты смешные видео смешные истории из соцсетей

GitHub Repository

ericmj/postgrex ericmj/postgrex

PostgreSQL driver for Elixir

http://hexdocs.pm/postgrex/

Language: Elixir

Created: September 08, 2013 15:10

Last updated: March 16, 2015 02:02

Last pushed: March 15, 2015 11:29

Size: 1.87 MB

Stars: 113

Forks: 36

Watchers: 13

Open issues: 4

Top Contributors

Eric Meadows-Jönsson José Valim Keitaroh Kobayashi Troy Kruthoff Martin Schürrer Paulo Almeida Joe Quadrino Adam Wright Andrew Forward Yurii Rashkovskii Andrea Leopardi David Rouchy Eduardo Gurgel Joe Honzawa Wojciech Kaczmarek Louis Pilfold

Releases

  • 0.8.0 - February 26, 2015 16:00
  • 0.7.0 - January 20, 2015 16:15
  • 0.6.0 - September 07, 2014 15:54
  • 0.5.5 - August 20, 2014 16:45
  • 0.5.4 - August 03, 2014 23:10
  • 0.5.3 - July 13, 2014 20:36
  • 0.5.2 - June 18, 2014 21:15
  • 0.5.1 - May 24, 2014 12:13
  • 0.5.0 - May 01, 2014 18:29
  • 0.4.2 - April 22, 2014 12:26

Related Projects

cloudi_service_db_pgsql 1.4.0
Erlang/Elixir Cloud Framework PostgreSQL Service
Hex - Erlang - BSD-3-Clause - Updated 2 months ago
datomex 0.0.5
Low level Elixir driver for the Datomic Database.
Hex - Elixir - MIT - Updated 4 months ago - 3 stars
decimal 1.1.0
Arbitrary precision decimal arithmetic for Elixir.
Hex - Elixir - Apache-2.0 - Updated 3 months ago - 22 stars
diver 0.1.1
A HBase driver for Erlang/Elixir using jinterface and the Asynchbase Java client to query the dat...
Hex - Java - Apache-2.0 - Updated 5 months ago - 15 stars
ex2ms 1.3.0
Translates Elixir functions to match specifications for use with `ets`.
Hex - Elixir - Apache-2.0 - Updated 7 months ago - 9 stars
веселые картинки развлекательные гифки интресные факты смешные видео смешные истории из соцсетей