Fork me on GitHub
Digital Commons

go-ruby-activerecord

Rails' ActiveRecord ORM core in Go โ€” SQL generation, associations & validations, .

Relation โ†’ SQLbelongs_to ยท has_manyschema DDLvalidationsSQLite ยท PG ยท MySQLAdapter seamMRI byte-exact100% coverage6 arches
Documentation (MkDocs Material + mike) Go 1.26.4+ Coverage 100%
zsh
$ go get github.com/go-ruby-activerecord/activerecord@latest

go-ruby-activerecord is a pure-Go (no cgo) reimplementation of the deterministic core of Rails' ActiveRecord ORM โ€” the query-building, schema-DDL, association, validation and attribute layers that turn a model plus a relation description into SQL, exactly as MRI's activerecord gem does. A lazy, chainable Relation (Where / Order / Joins / aggregates) renders through ToSQL; belongs_to / has_many / has_one / HABTM / :through emit ActiveRecord's exact join geometry; validations produce an Errors object shaped like ActiveModel::Errors; and three dialects (SQLite / PostgreSQL / MySQL) handle quoting and literals. The one thing that genuinely needs a database โ€” executing the SQL โ€” is an injected Adapter host seam (wired to go-ruby-sqlite3 / go-ruby-pg), so the module stays 100% Ruby- and CGO-free while a differential oracle compares its output to ActiveRecord's own Relation#to_sql byte-for-byte.

Relation & ToSQL ready

A lazy, immutable, chainable Relation โ€” Where (hash / ?- and :name-placeholders / IN / BETWEEN / IS NULL), Not, Or, Select, Order, Limit/Offset, Group/Having, Distinct, Merge, named scopes โ€” rendered to SQL by ToSQL(), plus aggregate and DML string builders.

Associations & joins ready

belongs_to / has_many / has_one / has_and_belongs_to_many and :through, emitting ActiveRecord’s exact INNER / LEFT OUTER JOIN โ€ฆ ON geometry โ€” including HABTM join tables and the two-hop through join with source-reflection direction.

Schema DDL ready

CreateTable (with References / Timestamps / NoPrimaryKey), AddColumnSQL, AddIndexSQL (unique, default index_<t>_on_<cols> name), AddForeignKeySQL, and a per-dialect column-type map โ€” the migration DDL ActiveRecord generates.

Validations & Errors ready

presence / length / format / numericality / inclusion / exclusion / uniqueness producing an Errors object shaped like ActiveModel::Errors, with ActiveRecord’s default message text and full_messages ordering.

Attributes & dirty tracking ready

Attribute readers / writers, per-column type casting, and dirty tracking (Changed / Changes / AttributeChanged) mirroring ActiveModel::Dirty.

Dialects (SQLite / PG / MySQL) ready

SQLite, PostgreSQL and MySQL identifier quoting and value literalization, selectable per model โ€” the same three dialects ActiveRecord ships, chosen where the generated SQL differs.

Differential oracle & coverage ready

Generated SQL, errors.full_messages and the schema DDL are compared to the real activerecord gem’s Relation#to_sql byte-for-byte; 100% coverage, gofmt + go vet clean, green across all six 64-bit Go arches and three OSes.

A faithful port of ActiveRecord's SQL generation and validations in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. It renders relations, association joins, schema DDL and validation messages, and literalizes for three dialects. Correctness is pinned by a differential oracle against the real activerecord gem โ€” generated SQL, errors.full_messages and DDL compared byte-for-byte. It is the ORM backend bound into go-embedded-ruby (rbgo), and a standalone, reusable module โ€” a sibling of go-ruby-sequel in the github.com/go-embedded-ruby ecosystem.