singlestore-labs / singlestoredb-laravel-driver

The official SingleStore Laravel driver.
https://github.com/singlestore-labs/singlestore-laravel-driver
Apache License 2.0
223 stars 22 forks source link

Implement Sort Key per-column direction feature #29

Closed miguilimzero closed 2 years ago

miguilimzero commented 2 years ago

This pull request implements the Sort Key per-column direction feature using the following syntax:

$table->sortKey([['f_name', 'asc'], ['l_name', 'desc']]);

The developer must use the second argument to set the direction for all columns or set a per-column direction for all columns:

$table->sortKey(['f_name', 'l_name'], 'desc'); // Correct (as before)

$table->sortKey([['f_name', 'asc'], ['l_name', 'desc']]); // Correct (now implemented)

$table->sortKey(['f_name', ['l_name', 'desc']]); // Throw exception

$table->sortKey(['f_name', ['l_name', 'asc']], 'desc'); // Throw exception

Note: A dummy index name was added to the shard key & sort key to support the array column syntax (This prevents Laravel from trying to auto-generate the index name from the column name). It does not impact the schema generation since the driver does not use this name attribute.

@carlsverre Let me know if this was the intended behavior! I didn't understand exactly how it was supposed to be implemented.

carlsverre commented 2 years ago

Do you mind adding one or two tests for the failure cases? Just to make sure that we don't regress in the future. Otherwise this PR looks solid! Thank you!

miguilimzero commented 2 years ago

@carlsverre done!