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:
- Performance
- Simplicirt
- 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()
- Compile-time safety
- No type casting
- Predictable results
2. Fluent & Clean API
Readable query chaining like natural language:
client.Model(&User{}).
Where("active = ?", true).
OrderBy("created_at DESC").
Find()
- Simple learning curve
- Familiar to GORM users
- 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
- Auto migrations
- Auto Go struct generation
- 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()
- Prevents unnecessary data loading
- Reduces DB cost
- Supports field-level selection
5. Smart CRUD Operations
user := &User{Name: "Alice", Email: "alice@example.com"}
client.Model(user).Save() // Insert
user.Name = "Bob"
client.Model(user).Save() // Update
client.Model(user).Delete() // Delete
- Automatic insert/update detection
- Less boilerplate
6. Transactions Made Simple
err := client.WithTx(func(tx *client.Tx) error {
tx.Create(&order)
tx.Update(&inventory)
return nil
})
- Safe rollback handling
- Clean transactional flow
7. Raw SQL Support (Escape Hatch)
client.Raw("SELECT * FROM users WHERE email LIKE $1", "%@gmail.com").
Scan(&users)
- Full control when needed
- 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
Top comments (0)