ydb-sdk-lite
raw JSON → 2.1.0 verified Sat Apr 25 auth: no javascript
ydb-sdk-lite v2.1.0 is a lightweight alternative to the official YDB Node.js SDK, optimized for low require time (~100ms vs 300ms) and small size (~5MB vs 40MB). Developed by Vitaliy Potapov, it supports DDL queries, automatic parameter type inference, and is designed for serverless environments. It currently only supports primitive types. The package ships TypeScript definitions and is released as needed.
Common errors
error TypeError: Class constructor Ydb cannot be invoked without 'new' ↓
cause Importing Ydb incorrectly: using a default import instead of named import, then trying to call it as a function without new.
fix
Use const { Ydb } = require('ydb-sdk-lite') or import { Ydb } from 'ydb-sdk-lite' and then new Ydb(...).
error Error: Unsupported type: Optional<...> ↓
cause Query uses a complex type not supported by ydb-sdk-lite.
fix
Only use primitive types; avoid Optional, List, Dict, etc., or switch to official ydb-sdk.
error Cannot find module 'ydb-sdk-lite' ↓
cause Package not installed or typo in package name.
fix
Run npm install ydb-sdk-lite and ensure import path is correct.
Warnings
gotcha Only primitive types are supported (Int8, Int16, Int32, Int64, Uint8, Uint16, Uint32, Uint64, Float, Double, String, Utf8, Bool, Date, Datetime, Timestamp). Complex types like Optional, List, Dict, Struct, Tuple are not supported. ↓
fix Use only columns with primitive types or fall back to official ydb-sdk for complex types.
gotcha executeDataQuery only works for DML queries (SELECT, INSERT, UPDATE, DELETE). DDL or other YQL statements must use executeYql. ↓
fix Use executeYql for DDL queries like CREATE TABLE, DROP TABLE, etc.
gotcha The package is lightweight and intended for serverless use. It may not handle all edge cases or large datasets as efficiently as the official SDK. ↓
fix If you need full YDB feature set, use the official ydb-sdk package.
Install
npm install ydb-sdk-lite yarn add ydb-sdk-lite pnpm add ydb-sdk-lite Imports
- Ydb wrong
import Ydb from 'ydb-sdk-lite'correctimport { Ydb } from 'ydb-sdk-lite' - Ydb wrong
const Ydb = require('ydb-sdk-lite')correctconst { Ydb } = require('ydb-sdk-lite') - Ydb
import type { Ydb } from 'ydb-sdk-lite'
Quickstart
import { Ydb } from 'ydb-sdk-lite';
const ydb = new Ydb({
dbName: 'your-database',
iamToken: process.env.YDB_TOKEN ?? '',
tablePathPrefix: 'your/path'
});
// Execute a simple query
const [users] = await ydb.executeDataQuery('SELECT * FROM users');
console.log(users);
// Execute with parameters
const query = `
DECLARE $userId AS Int32;
SELECT * FROM users WHERE userId = $userId;
`;
const [user] = await ydb.executeDataQuery(query, { $userId: 42 });
console.log(user);
// Execute DDL
await ydb.executeYql('DROP TABLE IF EXISTS users');