Bool support and type related insert/select tests
Go Tests / test (push) Failing after 6s

This commit is contained in:
2026-05-12 08:59:37 +02:00
parent ffd9cd004e
commit 1642a01aad
5 changed files with 176 additions and 14 deletions
+45 -1
View File
@@ -4,6 +4,7 @@ import (
"errors"
"reflect"
"strings"
"time"
)
type Column struct {
@@ -51,7 +52,7 @@ func (c *Column) GetDDL() (string, error) {
func (c *Column) inlineModifiers() []string {
var mods []string
for k, _ := range c.Modifiers {
for k := range c.Modifiers {
switch k {
case "nn":
mods = append(mods, "NOT NULL")
@@ -80,3 +81,46 @@ func (c *Column) IsPK() bool {
_, ok := c.Modifiers["pk"]
return ok
}
// Encodes the value to be DB compatible
func (c Column) Encode(value reflect.Value) any {
typ := value.Type().String()
var encoded any
switch typ {
case "time.Time":
timeVal := value.Interface().(time.Time)
encoded = timeVal.UnixMilli()
case "bool":
boolVal := value.Interface().(bool)
if boolVal {
encoded = 1
} else {
encoded = false
}
default:
encoded = value.Interface()
}
return encoded
}
// Decodes the raw value from the DBs
func (c Column) Decode(expected string, rawValue reflect.Value) any {
var decoded any
switch expected {
case "time.Time":
decoded = time.UnixMilli(rawValue.Interface().(int64))
case "bool":
rawValue := rawValue.Interface().(int)
if rawValue > 0 {
decoded = true
} else {
decoded = false
}
default:
decoded = rawValue.Interface()
}
return decoded
}