Skip to content

scrimbles/beer-me

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

beer-me

A template query management tool. Define your common queries once, run them anywhere, with arbitrary filters.

beer-me [environment] <resource> [-f filter]

How It Works

beer-me composes SQL queries from three things:

  1. A resource template — a .sql file with your base query (no WHERE, no ;)
  2. An environment — a named database connection from .envlist
  3. Filters — injected at runtime via -f

Without an environment argument, beer-me just prints the query. With one, it executes it.

Usage

# print the query (no execution)
beer-me record

# run against an environment
beer-me local record -f "id = 'some-uuid'"

# multiple filters (AND'd together)
beer-me local record -f "id = 'some-uuid'" -f "artist.age = 20"

Setup

Environments

Defined in ~/.config/beer-me/.envlist, tab-separated:

LOCAL	psql postgres://user:password@localhost:5432/my_database -c
STAGING	psql postgres://user:password@staging:5432/my_database -c

The first column is the environment name (case-insensitive, typically SCREAMING). The second is the command stub — beer-me concatenates the generated query to the end of it.

For psql, that means the stub must end with -c.

Resources

A resource is a template query stored at ~/.config/beer-me/<resource-name>.sql:

SELECT
    table_1.*,
    table_2.important_info AS table_2_info
FROM table_1
JOIN table_2 ON table_1.id = table_2.table_1_id

Two rules:

  • No =WHERE= clause — beer-me builds this from your -f flags
  • No trailing =;= — beer-me appends it after filter injection

Filters

Filters are appended as WHERE conditions, joined with AND:

beer-me record -f "column_name = 'value'"
beer-me record -f "\"column_name\" = 'double quotes'"

Sister Project

handroll — spec-driven test data generation. beer-me investigates the data, handroll generates it.

About

A template query management tool

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages