Skip to content

fix: preserve datetime strings in SQLite to maintain original formatting #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion core/src/plugins/sqlite3/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,35 @@ package sqlite3

import (
"strings"

mapset "github.com/deckarep/golang-set/v2"
)

var (
// SQLite datetime-related types that should be preserved as strings
dateTimeTypes = mapset.NewSet("DATE", "DATETIME", "TIMESTAMP")
)

// ConvertStringValueDuringMap preserves datetime strings since SQLite stores them as TEXT
func (p *Sqlite3Plugin) ConvertStringValueDuringMap(value, columnType string) (interface{}, error) {
return value, nil
// For consistency with ConvertStringValue, we preserve datetime strings
// and delegate to ConvertStringValue for all type handling
return p.ConvertStringValue(value, columnType)
}

// ConvertStringValue overrides the base implementation to preserve datetime strings
// Since SQLite stores DATETIME as TEXT, we should not parse and reformat datetime values
func (p *Sqlite3Plugin) ConvertStringValue(value, columnType string) (interface{}, error) {
// Normalize column type to uppercase for comparison
normalizedType := strings.ToUpper(columnType)

// For datetime-related types, preserve the original string value
if dateTimeTypes.Contains(normalizedType) {
return value, nil
}

// For all other types, delegate to the base GORM implementation
return p.GormPlugin.ConvertStringValue(value, columnType)
}

func (p *Sqlite3Plugin) GetPrimaryKeyColQuery() string {
Expand Down