From 3d2d52a1d9f2d3850a439768486f7ec6e5666cfa Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Oct 2025 08:59:35 +0300 Subject: [PATCH 1/3] feat: update javascript/typescript connection example to use new sdk --- .../ConnectToDB/ConnectToDBDialog.tsx | 2 +- src/components/ConnectToDB/i18n/en.json | 2 +- src/components/ConnectToDB/snippets.ts | 35 +++++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/components/ConnectToDB/ConnectToDBDialog.tsx b/src/components/ConnectToDB/ConnectToDBDialog.tsx index 78f88cda78..962f5d8bf6 100644 --- a/src/components/ConnectToDB/ConnectToDBDialog.tsx +++ b/src/components/ConnectToDB/ConnectToDBDialog.tsx @@ -28,7 +28,7 @@ const connectionTabs: {id: SnippetLanguage; title: string}[] = [ {id: 'csharp', title: 'C# (.NET)'}, {id: 'go', title: 'Go'}, {id: 'java', title: 'Java'}, - {id: 'javascript', title: 'Node JS'}, + {id: 'javascript', title: 'JavaScript/TypeScript'}, {id: 'php', title: 'PHP'}, {id: 'python', title: 'Python'}, ]; diff --git a/src/components/ConnectToDB/i18n/en.json b/src/components/ConnectToDB/i18n/en.json index 0fdf24e6bd..a0e388fe11 100644 --- a/src/components/ConnectToDB/i18n/en.json +++ b/src/components/ConnectToDB/i18n/en.json @@ -11,7 +11,7 @@ "docs_dotnet": "https://ydb.tech/docs/en/dev/example-app/example-dotnet", "docs_go": "https://ydb.tech/docs/en/dev/example-app/go", "docs_java": "https://ydb.tech/docs/en/dev/example-app/java", - "docs_nodejs": "https://ydb.tech/docs/en/dev/example-app/example-nodejs", + "docs_nodejs": "https://ydb.js.org", "docs_php": "https://ydb.tech/docs/en/dev/example-app/example-php", "docs_python": "https://ydb.tech/docs/en/dev/example-app/python" } diff --git a/src/components/ConnectToDB/snippets.ts b/src/components/ConnectToDB/snippets.ts index c794ce89bf..64ecfd5ede 100644 --- a/src/components/ConnectToDB/snippets.ts +++ b/src/components/ConnectToDB/snippets.ts @@ -123,27 +123,26 @@ public class YDBConnect { } export function getNodeJSSnippetCode({database, endpoint}: SnippetParams) { - return `const {Driver, getCredentialsFromEnv, getLogger} = require('ydb-sdk'); + return `// Requires Node.js 20.19 or higher (also works with Deno/Bun) +// Documentation: https://ydb.js.org +// Source code: https://github.com/ydb-platform/ydb-js-sdk +// Examples: https://github.com/ydb-platform/ydb-js-examples +import {Driver} from '@ydbjs/core'; +import {query} from '@ydbjs/query'; +import type {ResultSet} from '@ydbjs/query'; -const logger = getLogger({level: 'debug'}); -const endpoint = '${endpoint ?? ''}'; -const database = '${database ?? '/'}'; -const authService = getCredentialsFromEnv(); -const driver = new Driver({endpoint, database, authService}); +const connectionString = 'grpc://${endpoint ?? ''}${database ?? '/'}'; + +const driver = new Driver(connectionString); async function run() { - if (!await driver.ready(100)) { - logger.fatal('Driver has not become ready in 10 seconds!'); - process.exit(1); - } - - await driver.tableClient.withSession(async (session) => { - res = await session.executeQuery("SELECT 'Hello, world!'") - console.log(res.resultSets[0].rows[0].items[0].bytesValue.toString()) - return - }); - - process.exit(0) + await driver.ready(); + const sql = query(driver); + + const resultSets: ResultSet[] = await sql\`SELECT 'Hello, world!' AS message;\`; + console.log(resultSets[0].rows[0].message); + + await driver.close(); } run();`; From efc93a5fc4aa525efc356e61847f691fe74758b1 Mon Sep 17 00:00:00 2001 From: Vladislav Polyakov Date: Mon, 13 Oct 2025 13:03:51 +0300 Subject: [PATCH 2/3] fix(examples): update nodejs examples link Signed-off-by: Vladislav Polyakov --- src/components/ConnectToDB/i18n/en.json | 2 +- src/components/ConnectToDB/snippets.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/ConnectToDB/i18n/en.json b/src/components/ConnectToDB/i18n/en.json index a0e388fe11..e941cab593 100644 --- a/src/components/ConnectToDB/i18n/en.json +++ b/src/components/ConnectToDB/i18n/en.json @@ -11,7 +11,7 @@ "docs_dotnet": "https://ydb.tech/docs/en/dev/example-app/example-dotnet", "docs_go": "https://ydb.tech/docs/en/dev/example-app/go", "docs_java": "https://ydb.tech/docs/en/dev/example-app/java", - "docs_nodejs": "https://ydb.js.org", + "docs_nodejs": "https://github.com/ydb-platform/ydb-js-examples", "docs_php": "https://ydb.tech/docs/en/dev/example-app/example-php", "docs_python": "https://ydb.tech/docs/en/dev/example-app/python" } diff --git a/src/components/ConnectToDB/snippets.ts b/src/components/ConnectToDB/snippets.ts index 64ecfd5ede..cc120fe32b 100644 --- a/src/components/ConnectToDB/snippets.ts +++ b/src/components/ConnectToDB/snippets.ts @@ -138,7 +138,7 @@ const driver = new Driver(connectionString); async function run() { await driver.ready(); const sql = query(driver); - + const resultSets: ResultSet[] = await sql\`SELECT 'Hello, world!' AS message;\`; console.log(resultSets[0].rows[0].message); @@ -168,7 +168,7 @@ $config = [ // 'root_cert_file' => './CA.pem', Root CA file (uncomment for dedicated server only) ], - 'credentials' => new AccessTokenAuthentication('') // use from reference/ydb-sdk/auth + 'credentials' => new AccessTokenAuthentication('') ]; $ydb = new Ydb($config);`; From 19c9699dfeb3de96d1f9b9f50c2b72e48f7627f9 Mon Sep 17 00:00:00 2001 From: Vladislav Polyakov Date: Tue, 21 Oct 2025 09:27:01 +0300 Subject: [PATCH 3/3] Fix connection string format by removing 'grpc://' --- src/components/ConnectToDB/snippets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ConnectToDB/snippets.ts b/src/components/ConnectToDB/snippets.ts index cc120fe32b..50a806bff3 100644 --- a/src/components/ConnectToDB/snippets.ts +++ b/src/components/ConnectToDB/snippets.ts @@ -131,7 +131,7 @@ import {Driver} from '@ydbjs/core'; import {query} from '@ydbjs/query'; import type {ResultSet} from '@ydbjs/query'; -const connectionString = 'grpc://${endpoint ?? ''}${database ?? '/'}'; +const connectionString = '${endpoint ?? ''}${database ?? '/'}'; const driver = new Driver(connectionString);