mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-09-08 15:41:18 +02:00
added Record.GetInt64(field) helper
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user