explaingit

go-gorp/gorp

3,756GoAudience · developerComplexity · 2/5Setup · easy

TLDR

gorp is a Go library that maps your Go structs to SQL database tables, so you can insert, update, and fetch rows without writing repetitive boilerplate SQL for every operation.

Mindmap

mindmap
  root((gorp))
    What it does
      SQL ORM helper
      Struct mapping
      Go database layer
    Features
      CRUD operations
      Lifecycle hooks
      Optimistic locking
      Transactions
    Databases
      PostgreSQL
      MySQL
      SQLite
    Use Cases
      Cut boilerplate SQL
      Fetch into structs
      Custom data hooks
    Status
      Low activity
      Best-effort maintenance
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Insert and fetch database rows by passing Go structs directly instead of writing raw SQL for every table

USE CASE 2

Run arbitrary SQL queries and have the results automatically populated into a slice of structs

USE CASE 3

Add pre- and post-operation hooks to run custom logic whenever a row is inserted, updated, or deleted

USE CASE 4

Use optimistic locking with a version column to prevent two processes from overwriting each other's changes

Tech stack

GoSQLSQLitePostgreSQLMySQL

Getting it running

Difficulty · easy Time to first run · 30min

Development is low-activity and maintained on a best-effort basis, consider active alternatives for new projects.

License terms are not described in the README.

In plain English

gorp is a Go library that reduces the repetitive work of reading and writing data to a SQL database. When you build a Go application that needs to store data, you typically write a lot of similar code to convert between Go structs and database rows: insert this struct, update that one, fetch rows and populate these fields. gorp handles that conversion for you based on how your structs are defined. You connect gorp to a database using Go's standard database/sql package, then register your struct types and tell gorp which table each one maps to and which field is the primary key. After that, you can insert, update, delete, and fetch rows by passing struct values directly rather than writing raw SQL for every operation. Auto-incrementing primary keys are read back and set on the struct after an insert. You can also run arbitrary SQL queries and have the results bound into a slice of structs without manual type assertions. The library supports pre and post hooks on insert, update, and delete operations, which lets you run custom logic around data changes. There is optional optimistic locking using a version column, which prevents one process from overwriting changes made by another. Transaction support is included. The README also mentions optional SQL query logging for debugging. gorp works with several SQL databases by using dialect-specific configuration objects, so the same code can run against SQLite, PostgreSQL, MySQL, or others with minimal changes. The maintainers note in the README that development activity is low and the project is maintained on a best-effort basis, with pull requests merged occasionally. The library follows semantic versioning and supports the two most recent major versions of Go. It is available via standard Go module tooling.

Copy-paste prompts

Prompt 1
Show me how to set up gorp with a PostgreSQL database in Go, register a User struct to a users table, and insert and fetch rows.
Prompt 2
Help me write a gorp post-insert hook in Go that automatically sets a CreatedAt timestamp on my struct after every INSERT.
Prompt 3
Explain how to use gorp's optimistic locking feature with a version column to prevent concurrent write conflicts in a Go app.
Prompt 4
Show me how to run a custom SQL query with gorp and bind the results into a slice of Go structs without manual type assertions.
Open on GitHub → Explain another repo

← go-gorp on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.