DEV Community

Cover image for 🇺🇸 Glancer — Ask your Rails database questions in plain language
Ernane Ferreira for Vídeos de Ti

Posted on

🇺🇸 Glancer — Ask your Rails database questions in plain language

A Rails engine that allows you to query the database using natural language, with RAG and LLMs. No need to write any code.

Every Rails project reaches a point where someone on the team (product, support, management) needs data, but no one has time to write a quick query for them. You know the drill: a Slack message, a GitHub issue titled "how many users signed up last week?", or a CSV request that ends up in someone's backlog.

So, I think about Glancer.

Demo

What it is

Glancer is a Ruby on Rails engine that mounts a full chat interface at /glancer inside your app. You type a question in plain language, it retrieves the relevant schema context, generates a SELECT query (or an ActiveRecord expression), validates and executes it safely, then returns the result with a human-readable explanation.

"How many orders were placed in the last 30 days, grouped by status?"
→ SELECT executed, results shown, answer written in plain language.
Enter fullscreen mode Exit fullscreen mode

It is inspired by Blazer, but instead of writing SQL yourself, you just ask.

Getting started

Add it to your Gemfile:

gem "glancer"
Enter fullscreen mode Exit fullscreen mode

Run the generator:

rails generate glancer:install
rails db:migrate
rails glancer:index:all
Enter fullscreen mode Exit fullscreen mode

Then visit /glancer and start asking questions.

The generator creates an initializer where you configure your LLM provider. A minimal setup with Gemini looks like this:

Glancer.configure do |config|
  config.llm_provider   = :gemini
  config.llm_model      = "gemini-2.0-flash"
  config.gemini_api_key = ENV["GEMINI_API_KEY"]

  config.schema_permission = true
end
Enter fullscreen mode Exit fullscreen mode

OpenAI and OpenRouter are also supported. It runs on top of RubyLLM, so any model it supports works here too. You can assign different models per role: a smarter model for query generation, a cheaper one for writing the response.

What it can do

A few things worth knowing:

Safety is not optional. Every query runs inside a transaction that always rolls back. The keyword blocklist rejects DELETE, UPDATE, INSERT, DROP, and friends before they even touch the executor. You can also point it at a read-only replica.

No extra infrastructure. Embeddings live in your existing database as a JSON column. No Pinecone, no Weaviate, nothing to set up.

It understands your domain. You can drop a Markdown file at config/glancer/llm_context.glancer.md and teach Glancer your business rules — what status values mean, how revenue is calculated, which columns to ignore:

- `orders.status` values: "pending" | "paid" | "shipped" | "refunded"
- Monthly revenue = SUM(orders.total) WHERE status = "paid"
- When asked about "churn", use the `churned_at` column on `subscriptions`
Enter fullscreen mode Exit fullscreen mode

The UI has some nice touches. Results render in a table with one-click CSV export. Charts are auto-generated where they make sense. Queries run in a background thread, so the main app thread stays free. You can type @table_name to pin a specific table to your question, edit the generated SQL inline and re-run it, and even dictate questions via microphone. There is also a schema viewer at /glancer/db-schema.

Blazer integration. If you already have Blazer installed, Glancer shows a button to open the generated SQL there directly.

The story behind it

This started as a study project. I had never published a gem before and wanted to understand the full process, from engine internals to gemspec to CI. I shared it with a few colleagues and they actually found it useful, so I decided to put it out there for the community.

It is version 1.0.0.

If you try it, I would love to hear what you think, about the code or the idea itself. Issues and pull requests are open.

If you find it useful, a star on the repo goes a long way in helping more people discover it.

GitHub: https://github.com/ErnaneJ/glancer
RubyGems: https://rubygems.org/gems/glancer

Top comments (0)