# stephenafamo/bob

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/stephenafamo-bob).**

1,739 stars · 108 forks · Go · MIT

## Links

- GitHub: https://github.com/stephenafamo/bob
- Homepage: https://bob.stephenafamo.com
- awesome-repositories: https://awesome-repositories.com/repository/stephenafamo-bob.md

## Topics

`database` `golang` `hacktoberfest` `mysql` `orm` `postgres` `postgresql` `psql` `query-builder` `sql` `sqlite` `sqlite3`

## Description

This project is a database toolkit for Go that provides schema-to-object mapping, fluent query construction, and automated code generation. It functions as a framework for type-safe database access, enabling developers to interact with relational databases by generating models and interfaces directly from existing database schemas.

The toolkit distinguishes itself through a workflow that parses hand-written SQL files to generate type-safe functions, allowing for the integration of custom SQL while maintaining consistent result mapping. It supports modular customization through a plugin-based architecture and uses SQL-comment-based metadata to control the structure of generated code. Additionally, it simplifies development by automatically generating test data factories to streamline the setup of unit and integration tests.

Beyond core generation, the toolkit provides a comprehensive suite for managing the full lifecycle of database interactions. This includes fluent query building across multiple dialects, automated parameter sanitization to prevent SQL injection, and relational mapping that transforms flat query results into nested object structures. It also features lifecycle hooks for executing custom logic during database operations and supports incremental integration, allowing for partial adoption without requiring a full system migration.

## Tags

### Development Tools & Productivity

- [ORM Code Generators](https://awesome-repositories.com/f/development-tools-productivity/orm-code-generators.md) — Inspects database schemas to produce type-safe models, query functions, and test data factories for Go applications.
- [Go Type Generators](https://awesome-repositories.com/f/development-tools-productivity/go-type-generators.md) — Automates the creation of type-safe Go data structures directly from existing database schemas.
- [Schema-Driven Code Generators](https://awesome-repositories.com/f/development-tools-productivity/project-scaffolding-config-code-generation/code-generation/schema-driven-code-generators.md) — Analyzes existing database structures to produce type-safe models and interfaces, eliminating manual boilerplate.

### Software Engineering & Architecture

- [Database Schema Code Generators](https://awesome-repositories.com/f/software-engineering-architecture/openapi-specification-parsers/go-code-generators/specification-from-code-generators/code-from-specification-generators/database-schema-code-generators.md) — Inspects existing database schemas to produce type-safe code structures and interfaces that simplify data access and reduce boilerplate. ([source](https://github.com/stephenafamo/bob/blob/main/CHANGELOG.md))

### Data & Databases

- [ORM Relationship Querying](https://awesome-repositories.com/f/data-databases/database-query-builders/orm-relationship-querying.md) — The database toolkit fetches associated records automatically using preloading strategies and transforms flat query results into nested structures based on column naming conventions. ([source](https://github.com/stephenafamo/bob/blob/main/CHANGELOG.md))
- [Fluent Query Construction](https://awesome-repositories.com/f/data-databases/expression-based-data-querying/fluent-query-apis/sql-syntax-tree-construction/fluent-query-construction.md) — Provides a chainable interface for constructing complex SQL statements while ensuring syntax validity and type safety. ([source](https://github.com/stephenafamo/bob#readme))
- [Type-Safe Query Construction](https://awesome-repositories.com/f/data-databases/expression-based-data-querying/fluent-query-apis/sql-syntax-tree-construction/fluent-query-construction/type-safe-query-construction.md) — Constructs complex database queries using a fluent interface that ensures type safety and correct syntax.
- [Fluent Query Builders](https://awesome-repositories.com/f/data-databases/fluent-query-builders.md) — Provides a chainable, fluent interface for constructing complex SQL statements with type safety.
- [SQL Query Builders](https://awesome-repositories.com/f/data-databases/sql-query-builders.md) — Provides a fluent interface for constructing type-safe SQL queries across multiple dialects with automated parameter binding.
- [Typesafe Query Executions](https://awesome-repositories.com/f/data-databases/sql-query-execution/typesafe-query-executions.md) — Maps query results directly into defined structures to eliminate manual row scanning while managing transactions and prepared statements. ([source](https://bob.stephenafamo.com/docs))
- [Typesafe Query Generations](https://awesome-repositories.com/f/data-databases/sql-query-generation/typesafe-query-generations.md) — Analyzes hand-written SQL queries to generate reusable, type-safe functions that handle parameter binding and result mapping automatically. ([source](https://github.com/stephenafamo/bob/tree/main/website))
- [Type-Safe Database Clients](https://awesome-repositories.com/f/data-databases/type-safe-database-clients.md) — Executes SQL queries and maps results directly into Go structures to eliminate manual row scanning.
- [Database Lifecycle Hooks](https://awesome-repositories.com/f/data-databases/database-lifecycle-hooks.md) — Triggers custom logic automatically before or after database operations to maintain state and business rules.
- [Database Query Execution](https://awesome-repositories.com/f/data-databases/database-query-execution.md) — Enables dynamic modification of queries before execution and provides flexible retrieval methods for single records, lists, or cursors. ([source](https://bob.stephenafamo.com/docs/code-generation/queries))
- [Database Relationship Mappings](https://awesome-repositories.com/f/data-databases/database-relationship-mappings.md) — Maps associations between database tables to enable eager loading and recursive data retrieval through automated joins or secondary queries. ([source](https://bob.stephenafamo.com/vs/sqlboiler))
- [Database Transaction Management](https://awesome-repositories.com/f/data-databases/database-transaction-management.md) — Manages atomic database operations using interfaces that handle the transaction lifecycle and trigger associated hooks automatically. ([source](https://github.com/stephenafamo/bob/blob/main/CHANGELOG.md))
- [Model Persistence](https://awesome-repositories.com/f/data-databases/model-persistence.md) — Inserts generated model instances into the database while automatically handling required relationships to ensure data integrity. ([source](https://bob.stephenafamo.com/docs/code-generation/factories))
- [Object-Relational Mapping Frameworks](https://awesome-repositories.com/f/data-databases/object-relational-mapping-frameworks.md) — Transforms flat database result sets into nested object structures by interpreting table relationships.
- [SQL Comment Metadata](https://awesome-repositories.com/f/data-databases/query-performance-monitors/query-annotators/sql-comment-metadata.md) — Allows developers to annotate query metadata using SQL comments to control code generation and structure resulting data objects. ([source](https://bob.stephenafamo.com/docs/code-generation/queries))
- [Relational Mappings](https://awesome-repositories.com/f/data-databases/relational-mappings.md) — Transforms flat database query results into nested structures by automatically interpreting relationships between tables.
- [Schema Mappers](https://awesome-repositories.com/f/data-databases/schema-mappers.md) — Transforms relational database tables into structured Go objects while managing complex relationships.
- [SQL-to-Code Workflows](https://awesome-repositories.com/f/data-databases/sql-to-code-workflows.md) — Parses hand-written SQL files to generate type-safe functions and automated test suites.

### Security & Cryptography

- [SQL Injection Prevention](https://awesome-repositories.com/f/security-cryptography/sql-injection-prevention.md) — Generates database-specific placeholders for user-provided values automatically to prevent SQL injection vulnerabilities during query execution. ([source](https://bob.stephenafamo.com/docs/query-builder/intro))

### Testing & Quality Assurance

- [Test Data Factories](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-utilities-assertions/test-data-management/test-data-factories.md) — Generates helper objects and mock data factories to simplify the setup and teardown of database-backed tests.
- [Compile-Time Type Validation](https://awesome-repositories.com/f/testing-quality-assurance/type-assertions/compile-time-type-validation.md) — Validates database operations and parameter bindings at compile time to prevent runtime data access errors.
