v1.17.1
Release Date: January 11, 2026
A critical bug fix release that resolves database driver configuration issues during project initialization.
🐛 Bug Fixes
Database Driver Configuration Fix
Fixed a critical bug where SQLite and other non-PostgreSQL databases were not properly configured during project initialization.
Issue: #31 - Project Generation using SQLite use Postgres instead
Problem
When running goca init --database sqlite (or any database other than PostgreSQL), the generated project incorrectly included PostgreSQL dependencies and connection code:
goca init my-api --database sqlite
cd my-api
cat go.mod
# ❌ Showed: gorm.io/driver/postgres v1.5.4
# ✅ Expected: gorm.io/driver/sqlite v1.5.4Root Cause
The createGoMod() and createMainGo() functions in cmd/init.go had hardcoded PostgreSQL driver configuration:
- Base dependencies always included
gorm.io/driver/postgres - Main.go always imported
"gorm.io/driver/postgres" - Database connection always used
postgres.Open(dsn)
Solution
Made database driver configuration conditional based on the --database flag:
Updated
createGoMod(): Now properly switches between database drivers- PostgreSQL →
gorm.io/driver/postgres v1.5.4 - MySQL →
gorm.io/driver/mysql v1.5.2 - SQLite →
gorm.io/driver/sqlite v1.5.4 - SQL Server →
gorm.io/driver/sqlserver v1.5.2 - MongoDB →
go.mongodb.org/mongo-driver v1.12.1 - DynamoDB → AWS SDK v2 packages
- Elasticsearch →
github.com/elastic/go-elasticsearch/v8 v8.10.1
- PostgreSQL →
Updated
createMainGo(): Now generates database-specific imports and connection code- Correct driver import for each database type
- Conditional GORM import (only for SQL databases)
- Database-specific connection code (e.g.,
sqlite.Open(dsn)for SQLite)
Impact
- Before: Users could not successfully initialize projects with SQLite, MySQL, or other non-PostgreSQL databases
- After: All 8 supported database types now work correctly
✅ Verified Database Support
All database types have been tested and verified to generate correct configuration:
| Database | Driver Package | Status |
|---|---|---|
| PostgreSQL | gorm.io/driver/postgres | ✅ Working |
| PostgreSQL JSON | gorm.io/driver/postgres | ✅ Working |
| MySQL | gorm.io/driver/mysql | ✅ Working |
| SQLite | gorm.io/driver/sqlite | ✅ Fixed |
| SQL Server | gorm.io/driver/sqlserver | ✅ Fixed |
| MongoDB | go.mongodb.org/mongo-driver | ✅ Fixed |
| DynamoDB | AWS SDK v2 | ✅ Fixed |
| Elasticsearch | github.com/elastic/go-elasticsearch/v8 | ✅ Fixed |
📦 Example Usage
SQLite Project
goca init my-api --module github.com/user/my-api --database sqlite
cd my-api
cat go.modGenerated go.mod (Correct):
module github.com/user/my-api
go 1.21
require (
github.com/gorilla/mux v1.8.0
gorm.io/driver/sqlite v1.5.4
gorm.io/gorm v1.25.5
)
require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
)Generated main.go (Correct):
import (
// ...
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func connectToDatabase(cfg *config.Config) (*gorm.DB, error) {
dsn := cfg.GetDatabaseURL()
// ...
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
// ...
}MySQL Project
goca init my-api --module github.com/user/my-api --database mysqlGenerated dependencies:
gorm.io/driver/mysql v1.5.2github.com/go-sql-driver/mysql(transitive)
🔧 Technical Details
Files Modified
cmd/init.go:createGoMod()- Made database dependencies conditionalcreateMainGo()- Made driver imports and connection code conditional- Function signature updated to pass database type correctly
Code Changes
// Before (Bug)
baseDeps := `github.com/gorilla/mux v1.8.0
gorm.io/gorm v1.25.5
gorm.io/driver/postgres v1.5.4` // ❌ Always PostgreSQL
// After (Fixed)
baseDeps := `github.com/gorilla/mux v1.8.0`
switch database {
case DBSQLite:
baseDeps += `
gorm.io/gorm v1.25.5
gorm.io/driver/sqlite v1.5.4` // ✅ Correct driver
// ... other cases
}📖 Migration Guide
For Affected Users
If you created a project with --database sqlite (or other non-PostgreSQL) using v1.17.0 or earlier:
Update Goca:
bashgo install github.com/sazardev/goca@latestRecreate Project (Recommended):
bashgoca init my-api --module github.com/user/my-api --database sqliteOr Manual Fix (If you have custom code):
Update
go.mod:bash# Remove PostgreSQL driver go get gorm.io/driver/postgres@none # Add correct driver (e.g., SQLite) go get gorm.io/driver/sqlite@latest # Clean up go mod tidyUpdate
cmd/server/main.go:go// Change import - "gorm.io/driver/postgres" + "gorm.io/driver/sqlite" // Change connection - db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) + db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
🙏 Contributors
Special thanks to @domharvest for reporting this issue!
📥 Installation
# Go Install
go install github.com/sazardev/goca@v1.17.1
# Homebrew (macOS/Linux)
brew update
brew upgrade goca
# From Source
git clone https://github.com/sazardev/goca.git
cd goca
git checkout v1.17.1
go build -o goca .