question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Introduce a task-based API and remove Result<'T, 'E> API friction

See original GitHub issue

This is an attempt to tackle #64 right now, the functions Sql.execute, Sql.executeRow, Sql.executeNonQuery etc. return data in the form of Async<Result<'SomeType, exn>>

This is fine in many cases but it can cause friction when:

  • You don’t want Result and instead choose to try ... catch the SQL code only on rare occasions
  • You are working with task (for example in Saturn/Giraffe) and don’t want the syntax and performance overhead of converting between async and task

I propose to fix the problems above by introducing mutually exclusive namespaces within this same nuget package that offers different return types BUT with the exact API of the Sql functions:

  • Npgsql.FSharp stays the same and continue to return Async<Result<'T, exn>> (package stays backward-compatible without breaking changes)
  • Npgsql.FSharp.NoResult exposes API functions that return Async<'T>
  • Npgsql.FSharp.Tasks exposes API functions that return Task<'T> with the help of Ply

Yes, the downside is of course the duplication of code in each namespace but I think it is worth the effort of removing as much overhead as possible and of course we can extract the common parts in a module (the RowReader for example).

What do you think @aspnetde @TheAngryByrd @baronfel @ninofloris

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
Zaid-Ajajcommented, Dec 2, 2020

As of v3.12 the library has implemented the namespace Npgql.FSharp.Tasks which offers the exact same API but with tasks and without Result, I haven’t gotten around to fully test it but in principle it should work 🤞 can you please give it a try and let me know how it goes? I have also updated the README docs to reflect the changes

@vilinski Latest has now updated Npgsql to v5.0 and all existing tests worked without changes 😄

1reaction
aspnetdecommented, Dec 2, 2020

That’s great news! I will give it a try as soon as possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding the Whys, Whats, and Whens of ValueTask
In this post, I'll cover the newer ValueTask / ValueTask<TResult> types, which were introduced to help improve asynchronous performance in ...
Read more >
60+ Open APIs tried, tested and de-risked
This API provides a standardized mechanism for test case, test suite, and non-functional test model execution. This also includes allocation and provisioning of ......
Read more >
What Is a REST API? Examples, Uses & Challenges
REST, which stands for Representational State Transfer, is an architectural style for distributed hypermedia systems. Learn more about REST ...
Read more >
Enabling and Disabling Services
To enable and disable APIs and services you need: A Google Cloud project. To learn how to create a Google Cloud project, see...
Read more >
Prioritized Task Scheduling API - MDN Web Docs
The API is promise-based and supports the ability to set and change task priorities, to delay tasks being added to the scheduler, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found