Project

jade-sql

0.0
The project is in a healthy, maintained state
Query and mutation builders, schema generation from db/structure.sql, and an ActiveRecord-backed runtime for the Jade language. Renders typed queries to (String, List(Value)) and decodes rows into Jade structs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 0.1.0
 Project Readme

jade-sql

Type-safe SQL for Jade. Builds queries and mutations from a generated schema, renders them to (String, List(Value)), and runs them against ActiveRecord via a Task port that auto-decodes rows into typed Jade structs.

Install

# Gemfile
gem 'jade-sql'

Its dependency, the jade-lang gem (the Jade compiler/runtime), resolves from RubyGems automatically.

To execute queries at runtime, opt into the AR-backed task port:

# config/initializers/jade_sql.rb (or similar)
require 'jade-sql/runtime'

To get the rake task for schema generation:

# Rakefile (or lib/tasks/jade.rake)
load Gem.find_files('jade-sql/tasks.rake').first

At a glance

Generate a typed schema from db/structure.sql, then build a query against it. The result is a Q you render with to_sql or run with fetch_*; rows decode straight into your struct.

import Sql exposing (Selector, eq, to_expr)
import Sql.Query exposing (Q, field, from, join, select, where)
import Schema exposing (patients, appointments)

struct Visit = {
  name: String,
  reason: String
}

def scheduled_visits -> Q(Selector(Visit))
  p <- from(patients)
  a <- join(appointments, (a) -> { p.id |> eq(a.patient_id) })

  select(Visit(_, _))
    |> field(p.name)
    |> field(a.reason)
    |> where(a.status |> eq(to_expr("scheduled")))
end

Run it with scheduled_visits |> fetch_many — a Task(List(Visit), SqlError) that decodes each row into Visit.

Documentation

  • Building SQL — generate a schema, build queries (joins, sorting/grouping, pagination, aggregates, arrays, JSONB) and mutations (insert/update/delete, RETURNING, timestamps, UUIDs).
  • Running queries and mutationsfetch_* / execute, transactions, and testing without a database.