Introducing Go DB ORM (v1.0.1) — A Type-Safe, Fluent ORM for Go

Introducing Go DB ORM (v1.0.1) — A Type-Safe, Fluent ORM for Go

3
calendar_today agoschedule2 min read
— Originally published at dev.to

I’ve been working on an ORM for Go which is lightweight, easy to use, type-safe, and developer-friendly at its core.

The main goal of GoDB ORM is simple:

Make database handling in Go feel clean, predictable, and enjoyable — without heavy abstraction or hidden magic.

It is designed to feel like native Go, not a framework that hides what’s happening under the hood.

It also balances:

  1. Performance
  2. Simplicirt
  3. Flexibility

This is the first version of this package. So, it might not have all the features you expect from an ORM, and there could be some bugs in it.

But please give it a try. Your contributions, bug reports, feature requests, and feedback will be much appreciated.

Key Features:
1. Type-Safe Query Builder (Generic API)
No interface{} chaos — everything is strongly typed:

users, err := client.Query[User]().
    Where("city = ?", "Dhaka").
    Where("age > ?", 18).
    OrderBy("created_at DESC").
    Limit(10).
    Offset(20).
    All()
  1. Compile-time safety
  2. No type casting
  3. Predictable results

2. Fluent & Clean API
Readable query chaining like natural language:

client.Model(&User{}).
    Where("active = ?", true).
    OrderBy("created_at DESC").
    Find()
  1. Simple learning curve
  2. Familiar to GORM users
  3. Clean production code style

3. Schema-Driven Development (CLI Powered)
Define your database schema like this:

model User {
    id         int      @id
    name       string
    email      string
    city       string?
    created_at datetime
}

Then generate everything automatically:

godborm migrate godborm generate

  1. Auto migrations
  2. Auto Go struct generation
  3. Faster development workflow

4. Smart Relations with Include()

Load related data easily:

client.Query[Invoice]().
    Include("User:name,email").
    Include("Items:item_name,quantity").
    All()
  1. Prevents unnecessary data loading
  2. Reduces DB cost
  3. Supports field-level selection

5. Smart CRUD Operations

user := &User{Name: "Alice", Email: "*Emails are not allowed*"}
client.Model(user).Save()   // Insert

user.Name = "Bob"
client.Model(user).Save()   // Update

client.Model(user).Delete() // Delete
  1. Automatic insert/update detection
  2. Less boilerplate

6. Transactions Made Simple

err := client.WithTx(func(tx *client.Tx) error {
    tx.Create(&order)
    tx.Update(&inventory)
    return nil
})
  1. Safe rollback handling
  2. Clean transactional flow

7. Raw SQL Support (Escape Hatch)

client.Raw("SELECT * FROM users WHERE email LIKE $1", "%@gmail.com").
    Scan(&users)
  1. Full control when needed
  2. No restrictions

Lets Start Go DB ORM

Getting started takes only a few steps:

1. Install CLI

go install github.com/Anik2069/go-db-orm/cmd/godborm@latest

2. Initialize ORM

godborm init

This generates:
godborm.json /schema folder

3. Define Your Schema

model User {
    id         int      @id
    name       string
    email      string
    city       string?
    created_at datetime
}

model Post {
    id       int      @id
    title    string
    user_id  int      @foreign(User.id)
}

4. Run Migrations

godborm migrate

5. Generate Models

godborm generate --package main

6. Connect in Code

import "github.com/Anik2069/go-db-orm/godborm/client"

func main() {
    err := client.ConnectWithConfig()
    if err != nil {
        panic(err)
    }
    defer client.Close()
}
🛠 Config
{
    "schema": "./schema",
    "migrations": "./migrations",
    "driver": "postgres",
    "dsn": "postgresql://user:pass@localhost:5432/dbname?sslmode=disable"
}

Conclusion
This project is still evolving and actively improving. Contributions, feedback, bug reports, and feature ideas are highly welcome. If you’re interested in improving GoDB ORM, feel free to explore and contribute:

GitHub: https://github.com/Anik2069/go-db-orm

Let’s build something useful for the Go ecosystem together

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

Tuesday Coding Tip 02 - Template with type-specific API

Jakub Neruda - Mar 10

The Audit Trail of Things: Using Hashgraph as a Digital Caliper for Provenance

Ken W. Algerverified - Apr 28

go-intake v0.1.0: A Small Go Library for Messy Data Intake

firatcelik - Jun 9

Architecting a Local-First Hybrid RAG for Finance

Pocket Portfolio - Feb 25

Go-Gin & Bun ORM API Scaffolder

xaiphyr - Jun 17
chevron_left
126 Points3 Badges
1Posts
0Comments

Related Jobs

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!