From bf1f1640149313952e66a66b138490d1d42492d7 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Wed, 19 Aug 2026 21:41:22 +0300 Subject: [PATCH] added Record.GetInt64(field) helper --- CHANGELOG.md | 2 ++ core/record_model.go | 5 +++++ core/record_model_test.go | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ef3dae0..addc7d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Added new `DELETE /api/logs` endpoint and UI control to delete all logs without changing the `maxDays` retention setting. +- Added `Record.GetInt64(field)` helper (note that the serializable max safe integer of the `number` field is ~2^53-1). + - Added quotes around the default `Content-Disposition` serving filename in case custom name with special characters is provided. - Added `Cross-Origin-Opener-Policy:same-origin` to the default security response headers. diff --git a/core/record_model.go b/core/record_model.go index 81e7ee28..c8e8bba0 100644 --- a/core/record_model.go +++ b/core/record_model.go @@ -959,6 +959,11 @@ func (m *Record) GetInt(key string) int { return cast.ToInt(m.Get(key)) } +// GetInt64 returns the data value for "key" as an int64. +func (m *Record) GetInt64(key string) int64 { + return cast.ToInt64(m.Get(key)) +} + // GetFloat returns the data value for "key" as a float64. func (m *Record) GetFloat(key string) float64 { return cast.ToFloat64(m.Get(key)) diff --git a/core/record_model_test.go b/core/record_model_test.go index 48e4c634..04959e3d 100644 --- a/core/record_model_test.go +++ b/core/record_model_test.go @@ -899,6 +899,43 @@ func TestRecordGetInt(t *testing.T) { } } +func TestRecordGetInt64(t *testing.T) { + t.Parallel() + + scenarios := []struct { + value any + expected int64 + }{ + {nil, 0}, + {"", 0}, + {[]string{"true"}, 0}, + {map[string]int{"test": 1}, 0}, + {time.Now(), 0}, + {"test", 0}, + {123, 123}, + {2.4, 2}, + {1<<63 - 1, 1<<63 - 1}, + {"123", 123}, + {"123.5", 123}, + {false, 0}, + {true, 1}, + } + + collection := core.NewBaseCollection("test") + record := core.NewRecord(collection) + + for i, s := range scenarios { + t.Run(fmt.Sprintf("%d_%#v", i, s.value), func(t *testing.T) { + record.Set("test", s.value) + + result := record.GetInt64("test") + if result != s.expected { + t.Fatalf("Expected %v, got %v", s.expected, result) + } + }) + } +} + func TestRecordGetFloat(t *testing.T) { t.Parallel()