Skip to content

Sorting does not work #20

@mohsinsiyal-tsi

Description

@mohsinsiyal-tsi

Hi, I am trying to sort the data with sort key but it's not working.
Schema:

        $schema = [
            'AttributeDefinitions' => [
                [
                    'AttributeName' => 'id',
                    'AttributeType' => 'S',
                ],
                [
                    'AttributeName' => 'customer_id',
                    'AttributeType' => 'N',
                ],
                [
                    'AttributeName' => 'created_at',
                    'AttributeType' => 'S',
                ],
            ],
            'TableName' => $this->tableName,
            'KeySchema' => [
                [
                    'AttributeName' => 'id',
                    'KeyType' => 'HASH',
                ],
                [
                    'AttributeName' => 'created_at',
                    'KeyType' => 'RANGE',
                ],
            ],
            'StreamSpecification' => [
                'StreamEnabled' => true,
                'StreamViewType' => 'NEW_AND_OLD_IMAGES',
            ],
            'GlobalSecondaryIndexes' => [
                [
                    'IndexName' => 'gsi_0',
                    'Projection' => [
                        'ProjectionType' => 'ALL',
                    ],
                    'KeySchema' => [
                        [
                            'AttributeName' => 'customer_id',
                            'KeyType' => 'HASH',
                        ],
                        [
                            'AttributeName' => 'created_at',
                            'KeyType' => 'RANGE',
                        ],
                    ],
                    'BillingMode' => 'PAY_PER_REQUEST',
                ],
            ],
            'BillingMode' => 'PAY_PER_REQUEST',
        ];

Model:

class AuditLog extends Model
{
    protected $connection= 'dynamodb';
    protected $table = "";
    protected $primaryKey = 'id';
    protected $sortKey = 'created_at';
    protected $fillable = ["id", "log_text", "customer_id", "created_at"];
}

Controller:

$data = AuditLog::limit(5)->scanIndexForward(false)->scan();
$response = [
    "success" => true,
    "data" => $data, 
];
return response($response, 201);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions