Test app

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.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Creating tables

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:

  • Series
  • Seasons
  • Episodes

Once the tables are created, the method for getting information about data schema objects is called and the result of its execution is output.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Adding data

Adding data to the created tables using an UPSERT statement of YQL. A data update request is sent within a single request to the server with transaction auto-commit mode enabled.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Retrieving data with a Select

Retrieving data using a SELECT statement in YQL. Handling the retrieved data selection in the app.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Parameterized queries

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.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Scan queries

Making a scan query that results in a data stream. Streaming lets you read an unlimited number of rows and amount of data.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Multistep transactions

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.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Managing transactions

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.

C++ | C# (.NET) | Go | Java | Node.js | PHP | Python

Handling errors

For more information about error handling, see Error handling in the API.