kitar / laravel-dynamodb

A DynamoDB based Eloquent model and Query builder for Laravel.
MIT License
179 stars 27 forks source link

Filter on keys in map attribute type #43

Open bjugan opened 6 months ago

bjugan commented 6 months ago

Hi,

First, thanks for creating this great package :-)

Is there any way to filter on keys in the map attribute type?

Example: ->filter('person.name', 'John')

I'm still new to DynamoDb and I'm sorry if I'm missing something obvious.

Actually, I did a temporary hack to solve it. Seems to work for my use case, but not very well tested.

// Builder.php

public function where($column, $operator = null, $value = null, $boolean = 'and')
{
    // Convert column and value to ExpressionAttributes.
    if (! $column instanceof Closure) {
        // The column has nested keys
        if (Str::contains($column, '.')) {
            $column = Str::of($column)
                ->explode('.')
                ->map(fn ($attribute) => $this->expression_attributes->addName($attribute))
                ->implode('.');
        } else {
            $column = $this->expression_attributes->addName($column);
        }

        if ($value !== null) {
            $value = $this->expression_attributes->addValue($value);
        }
    }
   ...