Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Functions in table returned by `require("pgmoon")`:

Creates a new `Postgres` object from a configuration object. All fields are
optional unless otherwise stated. The newly created object will not
automatically connect, you must call `conect` after creating the object.
automatically connect, you must call `connect` after creating the object.

Available options:

Expand All @@ -122,7 +122,7 @@ Available options:
* `"ssl"`: enable ssl (default: `false`)
* `"ssl_verify"`: verify server certificate (default: `nil`)
* `"ssl_required"`: abort the connection if the server does not support SSL connections (default: `nil`)
* `"socket_type"`: the type of socket to use, one of: `"nginx"`, `"luasocket"`, `cqueues` (default: `"nginx"` if in nginx, `"luasocket"` otherwise)
* `"socket_type"`: the type of socket to use, one of: `"nginx"`, `"haproxy"`, `"luasocket"`, `"cqueues"` (default: `"nginx"` if in nginx, `"luasocket"` otherwise)
* `"application_name"`: set the name of the connection as displayed in `pg_stat_activity`. (default: `"pgmoon"`)
* `"pool"`: (OpenResty only) name of pool to use when using OpenResty cosocket (default: `"#{host}:#{port}:#{database}"`)
* `"pool_size"`: (OpenResty only) Passed directly to OpenResty cosocket connect function, [see docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect)
Expand Down
3 changes: 2 additions & 1 deletion pgmoon-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package = "pgmoon"
version = "dev-1"

source = {
url = "git://github.com/leafo/pgmoon.git"
url = "git://github.com/mecampbellsoup/pgmoon.git",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leafo we need this change so that I can ref my rockspec and get our forked pgmoon. After/when this PR is approved let's remove this change before merging 😄

tag = "luasocket-to-haproxy"
}

description = {
Expand Down
13 changes: 10 additions & 3 deletions pgmoon/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ do
settimeout = true
}
luasocket = {
tcp = function(...)
local socket = require("socket")
local sock = socket.tcp(...)
tcp = function(socket_type, ...)
local sock
if socket_type == "haproxy" then
sock = core.tcp(...)
else
local socket = require("socket")
sock = socket.tcp(...)
end
local proxy = setmetatable({
sock = sock,
send = function(self, ...)
Expand Down Expand Up @@ -98,6 +103,8 @@ return {
socket = ngx.socket.tcp()
elseif "luasocket" == _exp_0 then
socket = luasocket.tcp()
elseif "haproxy" == _exp_0 then
socket = luasocket.tcp(socket_type)
elseif "cqueues" == _exp_0 then
socket = require("pgmoon.cqueues").CqueuesSocket()
else
Expand Down
12 changes: 9 additions & 3 deletions pgmoon/socket.moon
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ luasocket = do
}

{
tcp: (...) ->
socket = require "socket"
sock = socket.tcp ...
tcp: (socket_type, ...) ->
local sock
if socket_type == "haproxy"
sock = core.tcp ...
else
socket = require "socket"
sock = socket.tcp ...
proxy = setmetatable {
:sock
send: (...) => @sock\send flatten ...
Expand Down Expand Up @@ -80,6 +84,8 @@ luasocket = do
ngx.socket.tcp!
when "luasocket"
luasocket.tcp!
when "haproxy"
luasocket.tcp(socket_type)
when "cqueues"
require("pgmoon.cqueues").CqueuesSocket!
else
Expand Down