Releases: leafo/pgmoon
v1.17.0 - PostgresPool and Unix Socket support
What's new
PostgresPool
A new pgmoon.pool module provides a connection pool that matches the Postgres interface, so it can be used as a drop-in replacement when you need to issue queries from multiple coroutines concurrently.
local PostgresPool = require("pgmoon.pool").PostgresPool
local pool = PostgresPool({
host = "127.0.0.1", database = "mydb", user = "postgres",
max_pool_size = 10
})
assert(pool:connect())
local res = assert(pool:query("select * from users limit 10"))For multi-query transactions, pool:reserve() / pool:release(pg) give you exclusive access to a single connection. Releasing a connection that's still in a transaction will automatically issue a ROLLBACK to keep the pool clean. See the README's PostgresPool section for the full API.
Unix socket connections (socket_path)
You can now connect over a Unix domain socket by passing socket_path to Postgres.new:
local pg = pgmoon.new({
socket_path = "/var/run/postgresql/.s.PGSQL.5432",
database = "mydb", user = "postgres",
})In OpenResty this uses the cosocket unix: syntax. Outside OpenResty it requires luaposix (luarocks install luaposix).
transaction_status
The Postgres object now exposes a transaction_status field that reflects the server's reported transaction state after each query: "I" (idle), "T" (in transaction), or "E" (failed transaction, awaiting ROLLBACK). This is also used by keepalive to auto-ROLLBACK dirty connections before returning them to the OpenResty pool.
Connection busy tracking
connect, query, disconnect, keepalive, and wait_for_notification now raise "pgmoon: connection is busy" if invoked while the connection is already mid-operation (e.g. from another coroutine that yielded mid-query) rather than silently corrupting the protocol stream. If you need concurrent access, use PostgresPool.
Other changes
- Add deserializer for
inet[]arrays (oid 1041) - More descriptive error message when the server requests a password but none was provided
- Doc fix for
pool_nameconfig option (#142) - Numerous README typo and example fixes
v1.16.0
https://luarocks.org/modules/leafo/pgmoon
Install
luarocks install pgmoon
OPM
opm install pgmoon
What's Changed
- use git+ssh protocol in rockspec source url by @mecampbellsoup in #126
- Add support for X509 signature algorithms such as RSA-SHA1 and ECDSA-with-SHA384 by @gsimko in #130
New Contributors
Full Changelog: v1.15.0...v1.16.0
v1.15 - Extended query protocol
https://luarocks.org/modules/leafo/pgmoon
https://opm.openresty.org/package/leafo/pgmoon/
Additions
- Add support for Postgres extended query protocol (using text transport) See https://github.com/leafo/pgmoon#extended-and-simple-query-protocols
- Add support for
pgmoon_serializemetamethod on objects to allow objects to describe how they can be serialized See https://github.com/leafo/pgmoon#custom-type-serializer - Implement
pgmoon_serializefor the includedPostgresArraytype - Add the
set_type_deserializermethod for easier configuration of deserialization (the undocumentedset_type_oidmethod is deprecated) See https://github.com/leafo/pgmoon#custom-type-deserializer
Changes
- The
querymethod can now take additional arguments to cause the query to be sent using the extended query protocol with parameters from the arguments - Array deserialization is now aware of the
NULLvalue and will returnpostgres.NULLinstead of the string"NULL" self.sockis no longer set tonilwhen callingdisconnectorkeepalive(you can reconnect again without allocating a new socket- Calling
disconnectwill now send a terminate message to the server before closing the socket, following the disconnection protocol - previously, on some errors, the socket would be disconnected. This is no longer the case, if message processing fails then the function returns the error result but the socket is left as is so you can continue to attempt operations on it
escape_literal()can now takepgmoon.NULLas a value and will returnNULLconvert_nullsis now a config option specified in the constructor- Minor performance optimizations to batch together network operations where possible
Misc
- Substantial updates to documentation: detailing new features, usage tips and examples, and other organizational updates
- Add test suite runner for openresty using
restycommand
v1.14.0
https://luarocks.org/modules/leafo/pgmoon
https://opm.openresty.org/package/leafo/pgmoon/
What's Changed
- pgmoon.crypto wil use resty.openssl / resty.string libraries when available if luaossl is not available @bungle in #117
- Socket is created on
connectif one doesn't already exist (due to previously disconnecting) #44 - Add ability to pass cqueues openssl context and automatic cqeues ssl context creation supports generic parameters for
ssl_version,ssl_verify, key and cert (see readme) #70 - Empty arrays will now generate valid syntax (
ARRAY[]) so you can cast it to the right type or have postgres throw a more meaningful error message - Refactored how configuration object is handled internally to prevent storing values directly on instance. (Note the original config object is kept referenced via metatable)
New Contributors
Full Changelog: https://github.com/leafo/pgmoon/compare/v1.13.0...v1.14.0###
v1.13.0
https://luarocks.org/modules/leafo/pgmoon
https://opm.openresty.org/package/leafo/pgmoon/
What's Changed
- Add support for scram_sha_256_auth by @murillopaula
- feat(socket) change LuaSec ssl_protocol default options by @jeremymv2 in #103
- Make application_name pg client init param configurable by @mecampbellsoup in #110
- feature: added 'backlog' and 'pool_size' options while using ngx.socket. by @xiaocang in #105
New Contributors
- @jeremymv2 made their first contribution in #103
- @mecampbellsoup made their first contribution in #110
- @xiaocang made their first contribution in #105
Full Changelog: v1.12.0...v1.13.0
v1.12.0
This update is required for the latest version of OpenResty: A compatibility change with how a number is converted from a pattern has caused a issue with how queries with an affected row count return.
https://luarocks.org/modules/leafo/pgmoon
Dependencies update:
There is now a guide on the top of the documentation listing all the optional dependencies for different environments. Because support for all versions of Lua has been added, Luabitop is no longer automatically installed as a dependency. This means that if you wish to use pgmoon with Lua 5.1 or 5.2 then you will need to install it manually:
$ luarocks install luabitopIf you are upgrading then you will already have it installed
Changes:
- Lua pattern to number compatibility fix (John Regan @jprjr)
- Support for Lua 5.1 through 5.4 (John Regan @jprjr)
- Fix bug where SSL version was not being passed when using LuaSec (Murillo Paula @murillopaula)
- Default to TLS v1.2 when using LuaSec
- Luabitop is no longer automatically installed as a default dependency (for Lua version compatibility)
- Migrate test suite from Travis to GitHub actions. Test suite now uses docker to spawn test postgres servers