0.0
No release in over 3 years
Connects LegionIO to PostgreSQL databases
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 1.5
>= 1.3.11
>= 1.4.9
>= 1.4.17
>= 1.2.1
 Project Readme

lex-postgres

A LegionIO extension (LEX) that connects LegionIO to PostgreSQL databases via the pg gem.

Installation

Add to your Gemfile:

gem 'lex-postgres'

Standalone Usage

require 'lex-postgres'

client = Legion::Extensions::Postgres::Client.new(
  host:     'db.example.com',
  port:     5432,
  dbname:   'myapp',
  user:     'jane.doe',
  password: 'secret'
)

# Execute arbitrary SQL
client.execute(sql: 'SELECT version()')
# => { result: [{ version: "PostgreSQL 16.0 ..." }] }

# Parameterized query
client.execute_params(sql: 'SELECT * FROM users WHERE id = $1', params: [42])
# => { result: [{ id: "42", name: "Jane Doe", email: "jane.doe@example.com" }] }

# List tables in a schema
client.list_tables(schema: 'public')
# => { result: ["orders", "products", "users"] }

# Describe a table's columns
client.describe_table(table: 'users')
# => { result: [{ column_name: "id", data_type: "integer", ... }, ...] }

# Total on-disk size of a table (bytes)
client.table_size(table: 'orders')
# => { result: 8192 }

Runner Methods

Queries

Method Description
execute(sql:) Run arbitrary SQL, returns rows as array of symbol-keyed hashes
execute_params(sql:, params: []) Parameterized query with $1, $2 placeholders

Tables

Method Description
list_tables(schema: 'public') List table names in the given schema
describe_table(table:, schema: 'public') Column definitions from information_schema.columns
table_size(table:) Total relation size in bytes via pg_total_relation_size

Connection Defaults

Option Default
host 127.0.0.1
port 5432
dbname postgres
user postgres
password nil (omitted if not set)

License

MIT