flesh out the scan a bit
This commit is contained in:
61
main.odin
61
main.odin
@@ -398,11 +398,64 @@ handle_query :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Request, r
|
||||
}
|
||||
|
||||
handle_scan :: proc(engine: ^dynamodb.Storage_Engine, request: ^HTTP_Request, response: ^HTTP_Response) {
|
||||
_ = engine
|
||||
_ = request
|
||||
table_name, ok := dynamodb.parse_table_name(request.body)
|
||||
if !ok {
|
||||
make_error_response(response, .ValidationException, "Invalid request or missing TableName")
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Implement scan operation in storage.odin
|
||||
make_error_response(response, .ValidationException, "Scan operation not yet implemented")
|
||||
// Parse Limit (default to 100 if not specified)
|
||||
limit := dynamodb.parse_limit(request.body)
|
||||
if limit == 0 {
|
||||
limit = 100
|
||||
}
|
||||
|
||||
// Parse ExclusiveStartKey if present
|
||||
// For now, we'll implement basic scan without ExclusiveStartKey parsing
|
||||
// TODO: Parse ExclusiveStartKey from request body and convert to binary key
|
||||
exclusive_start_key: Maybe([]byte) = nil
|
||||
|
||||
// Perform scan
|
||||
result, err := dynamodb.scan(engine, table_name, exclusive_start_key, limit)
|
||||
if err != .None {
|
||||
#partial switch err {
|
||||
case .Table_Not_Found:
|
||||
make_error_response(response, .ResourceNotFoundException, "Table not found")
|
||||
case:
|
||||
make_error_response(response, .InternalServerError, "Failed to scan table")
|
||||
}
|
||||
return
|
||||
}
|
||||
defer dynamodb.scan_result_destroy(&result)
|
||||
|
||||
// Build response
|
||||
builder := strings.builder_make()
|
||||
strings.write_string(&builder, `{"Items":[`)
|
||||
|
||||
for item, i in result.items {
|
||||
if i > 0 do strings.write_string(&builder, ",")
|
||||
item_json := dynamodb.serialize_item(item)
|
||||
strings.write_string(&builder, item_json)
|
||||
}
|
||||
|
||||
strings.write_string(&builder, `],"Count":`)
|
||||
fmt.sbprintf(&builder, "%d", len(result.items))
|
||||
strings.write_string(&builder, `,"ScannedCount":`)
|
||||
fmt.sbprintf(&builder, "%d", len(result.items))
|
||||
|
||||
// Add LastEvaluatedKey if present (pagination)
|
||||
if last_key, has_last := result.last_evaluated_key.?; has_last {
|
||||
// TODO: Convert binary key back to DynamoDB JSON format
|
||||
// For now, we'll just include it as base64 (not DynamoDB-compatible yet)
|
||||
_ = last_key
|
||||
// When fully implemented, this should decode the key and serialize as:
|
||||
// ,"LastEvaluatedKey":{"pk":{"S":"value"},"sk":{"N":"123"}}
|
||||
}
|
||||
|
||||
strings.write_string(&builder, "}")
|
||||
|
||||
resp_body := strings.to_string(builder)
|
||||
response_set_body(response, transmute([]byte)resp_body)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user