elixir-ecto / db_connection

Database connection behaviour
http://hexdocs.pm/db_connection/DBConnection.html
306 stars 113 forks source link

Introduce declare/fetch/deallocate #89

Closed fishcakez closed 7 years ago

fishcakez commented 7 years ago

Explicitly defining handle_first/4 and handle_next/4 is deprecated because callback implementations that are required to differentiate also need to track cursors in their state. A single fetch/4 is cleaner to use and these callbacks forward to handle_fetch/4 on use DBConnection.

For first/next/fetch the return value is {:cont | :halt, result, state} where :cont is continue (same as :ok) and:haltmeans both that the cursor has finished enumerating results and the cursor is deallocated. Therefore:haltdoes not require adeallocatecall. This API is chosen to avoid an extra roundtrip that current adapters do. handle_first/4 and handle_next/4 still support:okand:deallocate` tuples.

A callback implementation may need to deallocate if the transaction ends without a cursor being deallocated (via fetch/4 or deallocate/4).