Skip to content

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:

bash
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.4

Root 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:

  1. 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
  2. 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:

DatabaseDriver PackageStatus
PostgreSQLgorm.io/driver/postgres✅ Working
PostgreSQL JSONgorm.io/driver/postgres✅ Working
MySQLgorm.io/driver/mysql✅ Working
SQLitegorm.io/driver/sqlite✅ Fixed
SQL Servergorm.io/driver/sqlserver✅ Fixed
MongoDBgo.mongodb.org/mongo-driver✅ Fixed
DynamoDBAWS SDK v2✅ Fixed
Elasticsearchgithub.com/elastic/go-elasticsearch/v8✅ Fixed

📦 Example Usage

SQLite Project

bash
goca init my-api --module github.com/user/my-api --database sqlite
cd my-api
cat go.mod

Generated go.mod (Correct):

go
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):

go
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

bash
goca init my-api --module github.com/user/my-api --database mysql

Generated dependencies:

  • gorm.io/driver/mysql v1.5.2
  • github.com/go-sql-driver/mysql (transitive)

🔧 Technical Details

Files Modified

  • cmd/init.go:
    • createGoMod() - Made database dependencies conditional
    • createMainGo() - Made driver imports and connection code conditional
    • Function signature updated to pass database type correctly

Code Changes

go
// 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:

  1. Update Goca:

    bash
    go install github.com/sazardev/goca@latest
  2. Recreate Project (Recommended):

    bash
    goca init my-api --module github.com/user/my-api --database sqlite
  3. Or 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 tidy

    Update 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

bash
# 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 .


Released under the MIT License.