This section describes the code of same-type test apps implemented using YDB SDKs in different programming languages:
A test app performs the following steps:
Initializing a database connection
To interact with YDB, create an instance of the driver, client, and session:
- The YDB driver lets the app and YDB interact at the transport layer. The driver must exist throughout the YDB access lifecycle and be initialized before creating a client or session.
- The YDB client runs on top of the YDB driver and enables the handling of entities and transactions.
- The YDB session contains information about executed transactions and prepared queries, and is part of the YDB client context.
Creating tables to be used in operations on a test app. This step results in the creation of DB tables of the series directory data model:
Once the tables are created, the method for getting information about data schema objects is called and the result of its execution is output.
Retrieving data with a Select
Querying data using parameters. This query execution option is preferable as it allows the server to reuse the query execution plan for subsequent calls and also protects from such vulnerabilities as SQL Injection.
Making a scan query that results in a data stream. Streaming lets you read an unlimited number of rows and amount of data.
Multiple commands are executed within a single multistep transaction. The client-side code can be run between query executions. Using a transaction ensures that select queries made in its context are consistent with each other.
Transactions are managed through TCL Begin and Commit calls.
In most cases, instead of explicitly using Begin and Commit calls, it's better to use transaction control parameters in execute calls. This helps you avoid unnecessary requests to YDB and run your queries more efficiently.
For more information about error handling, see Error handling in the API.