Skip to content

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 SQLclient.execute(sql: 'SELECT version()')# => { result: [{ version: "PostgreSQL 16.0 ..." }] }# Parameterized queryclient.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 schemaclient.list_tables(schema: 'public')# => { result: ["orders", "products", "users"] }# Describe a table's columnsclient.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

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

Tables

MethodDescription
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

OptionDefault
host127.0.0.1
port5432
dbnamepostgres
userpostgres
passwordnil (omitted if not set)

License

MIT

About

LegionIO PostgreSQL extension

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages