ydb-nodejs-sdk icon indicating copy to clipboard operation
ydb-nodejs-sdk copied to clipboard

feat: Add support of `using` keyword for driver and session management

Open nikolaymatrosov opened this issue 2 years ago • 2 comments

Feature Request

Describe the Feature Request

The YDB SDK, like many database SDKs, offers interfaces for establishing sessions and interacting with the database through a driver. The addition of TypeScript support, specifically for a using keyword, would introduce several benefits for developers working with YDB.

As the support of this keyword was introduced in Typecscript 5.2, it would be great if its support will be added to the SDK.

Resource Management: The primary advantage of a using construct is automatic resource management. In the context of YDB, this would ensure that database sessions and connections are properly closed or disposed of once they are no longer needed, reducing the risk of resource leaks that could lead to performance issues or exceeding resource limits. Code Clarity and Maintenance: Using a using construct makes the scope of resource usage clear. It delineates where resources are started to be used and where they are released, making the code easier to understand and maintain. This is particularly beneficial in complex applications where resource management is critical.

Promote Best Practices: Encouraging the use of a using pattern or similar construct can promote best practices among developers. It makes resource management a more integral part of the development process, encouraging developers to think about the lifecycle of the resources they use.

Asynchronous Support: With the modern TypeScript ecosystem heavily relying on asynchronous operations, especially in the context of database operations, integrating using with async/await patterns would make managing asynchronous database sessions and connections more intuitive. This would allow developers to write non-blocking code while ensuring resources are automatically managed.

Describe Alternatives

I personally find callback approach for managing sessions a little bit cumbersome and I think that developer experience will be much smoother after this change.

Additional Context

Short introduction into using

If the feature request is approved, would you be willing to submit a PR? No

nikolaymatrosov avatar Feb 18 '24 13:02 nikolaymatrosov

Symbol.dispose and Symbol.asyncDispose appear in fresh builds of NodeJS 18 and 20. If NodeJS is not recently updated, these symbols may be missing.

So including this functionality in the SDK will require adding a polyfill. So far the polyfill that is found has some issues itself

Zork33 avatar Apr 02 '24 23:04 Zork33

Node 16 reached its end of life September 16th, 2023. blog So there's nothing wrong to drop its support.

nikolaymatrosov avatar Apr 03 '24 05:04 nikolaymatrosov