use new number type to be compatible with dynamo

This commit is contained in:
2026-02-16 08:45:30 -05:00
parent 089ef39bd9
commit f8b0b1c3ae
7 changed files with 680 additions and 45 deletions

View File

@@ -6,13 +6,15 @@ import "core:strings"
// DynamoDB AttributeValue - the core data type
Attribute_Value :: union {
String, // S
Number, // N (stored as string)
Number, // N = stored as string, I'm keeping this so we can still do the parsing/serialization
DDB_Number, // N Dynamo uses whole numbers and not floats or strings so we'll make that its own type
Binary, // B (base64)
Bool, // BOOL
Null, // NULL
String_Set, // SS
Number_Set, // NS
Binary_Set, // BS
DDB_Number_Set,// BS
List, // L
Map, // M
}
@@ -25,6 +27,7 @@ Null :: distinct bool
String_Set :: distinct []string
Number_Set :: distinct []string
DDB_Number_Set :: distinct []DDB_Number
Binary_Set :: distinct []string
List :: distinct []Attribute_Value
Map :: distinct map[string]Attribute_Value
@@ -382,6 +385,8 @@ attr_value_deep_copy :: proc(attr: Attribute_Value) -> Attribute_Value {
return String(strings.clone(string(v)))
case Number:
return Number(strings.clone(string(v)))
case DDB_Number:
return clone_ddb_number(v)
case Binary:
return Binary(strings.clone(string(v)))
case Bool:
@@ -400,6 +405,12 @@ attr_value_deep_copy :: proc(attr: Attribute_Value) -> Attribute_Value {
ns[i] = strings.clone(n)
}
return Number_Set(ns)
case DDB_Number_Set:
ddb_ns := make([]DDB_Number, len(v))
for num, i in v {
ddb_ns[i] = clone_ddb_number(num)
}
return DDB_Number_Set(ddb_ns)
case Binary_Set:
bs := make([]string, len(v))
for b, i in v {
@@ -427,6 +438,9 @@ attr_value_destroy :: proc(attr: ^Attribute_Value) {
switch v in attr {
case String:
delete(string(v))
case DDB_Number:
delete(v.integer_part)
delete(v.fractional_part)
case Number:
delete(string(v))
case Binary:
@@ -443,6 +457,12 @@ attr_value_destroy :: proc(attr: ^Attribute_Value) {
}
slice := v
delete(slice)
case DDB_Number_Set:
for num in v {
delete(num.integer_part)
delete(num.fractional_part)
}
delete(v)
case Binary_Set:
for b in v {
delete(b)