-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Zorkaltsev
authored and
Alexey Zorkaltsev
committed
Sep 14, 2023
1 parent
9c66dd7
commit b6ef655
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Examples in the folder are for the [article](https://ydb.tech/ru/docs/reference/ydb-sdk/recipes/tx-control) *Setting the transaction execution mode* | ||
|
||
To run examples | ||
|
||
Define *YDB_CONNECTION_STRING* and *YDB_TOKEN* environment variables | ||
|
||
Make new project by *npm i ydb-sdk* in clear folder | ||
|
||
And copy example code to this project | ||
|
||
``` | ||
npx ts-node <example name>.ts | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {Driver, TokenAuthService} from 'ydb-sdk'; | ||
|
||
(async function () { | ||
const driver = new Driver({ | ||
connectionString: process.env.YDB_CONNECTION_STRING, | ||
authService: new TokenAuthService(process.env.YDB_TOKEN as string), | ||
}); | ||
try { | ||
await driver.tableClient.withSession(async (session) => { | ||
const preparedQuery = await session.prepareQuery("SELECT 1"); | ||
const txMeta = await session.beginTransaction({serializableReadWrite: {}}); | ||
const txId = txMeta.id as string; | ||
await session.executeQuery(preparedQuery, {}, {txId}); | ||
await session.commitTransaction({txId}); | ||
}); | ||
} finally { | ||
await driver.destroy(); | ||
} | ||
})(); |