Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ConnectToDB/ConnectToDBDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
];
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConnectToDB/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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://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"
}
37 changes: 18 additions & 19 deletions src/components/ConnectToDB/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '<endpoint>'}';
const database = '${database ?? '/<database>'}';
const authService = getCredentialsFromEnv();
const driver = new Driver({endpoint, database, authService});
const connectionString = '${endpoint ?? '<endpoint>'}${database ?? '/<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();`;
Expand All @@ -169,7 +168,7 @@ $config = [
// 'root_cert_file' => './CA.pem', Root CA file (uncomment for dedicated server only)
],

'credentials' => new AccessTokenAuthentication('<token>') // use from reference/ydb-sdk/auth
'credentials' => new AccessTokenAuthentication('<token>')
];

$ydb = new Ydb($config);`;
Expand Down
Loading