How stephenafamo/bob works
Project Type & Purpose
• Bob is a Go “SQL Access Toolkit”: a library plus a set of CLI code‐generation tools and documentation.
• It exposes a fluent query‐builder + executor at runtime, and separate code generators (bobgen‑mysql, bobgen‑psql, bobgen‑sqlite, etc.) that read your DB schema and emit strongly typed Go models, factories, and queries.
High‐Level Components
A. CLI/Codegen Tools (build-time)
• Entry points: generate.go, build.go, binder.go, hooks.go
• Sub‐binaries: gen/bobgen‑mysql, bobgen‑psql, bobgen‑sqlite, bobgen‑sql
• Codegen engine: gen/ (drivers, templates, plugin.go)
B. Core Library (runtime)
• clause/ & expr/: SQL query builder modules (SELECT, JOIN, WHERE, etc.)
• exec.go: SQL executor wrapping database/sql
• query.go, orm/: higher‐level ORM query abstractions
• types/: custom DB types (JSON, PG enums, arrays, etc.)
C. Dialects
• dialect/mysql, dialect/psql, dialect/sqlite
• Each implements SQL variations and hints for that engine.
D. Consumer Application
• Your application imports “github.com/stephenafamo/bob” + generated code.
• At runtime it builds queries via clause+expr, executes them via exec, maps rows into generated structs.
E. Database(s)
F. Documentation Website
• website/: A Docusaurus‐powered site hosting user docs and examples.
Relationships & Data Flows
• Build‐time: CLI tools → connect to Database (database/sql + driver) → introspect schema → pass schema into gen/ drivers & templates → emit Go source files on disk.
• Run‐time: Application → imports Core Library + generated code → builds SQL via clause/expr → hands SQL to exec.go + dialect → database/sql driver → Database → returns rows → mapped back into Go structs.
• Documentation: independent site, static build of markdown content.
Architectural Patterns & Principles
• Builder pattern for SQL clause/expr modules.
• Plugin/driver pattern in gen/ for supporting multiple dialect codegens.
• Strict separation of build‐time (code gen) vs run‐time (query build + execution).
• Modular monorepo: clear separation of core, dialects, gen, website, tests.
Essential Elements
• Distinguish build‑time vs run‑time with a visual divider or background shading.
• Don’t omit the plugin/driver layer in gen/, and the dialect abstractions.