Typescript SDK

Load, query, and transform data using TypeScript or JavaScript.

The Birkini TypeScript SDK enables developers to interact with local, subscribed, and published data from both browser and NodeJS environments.

You can find the latest SDK documentation on GitHub. Below are quick examples to help you get started.

Installation

npm install @birkini/js-sdk
# or
yarn add @birkini/js-sdk

TypeScript Usage

import { Birkini } from '@birkini/js-sdk';

async function main() {
  const client = new Birkini('ACCESSKEY:SECRET:USERNAME');
  await client.login();

  const originalStudents = [
    { id: 1, name: 'Alice', active: true },
    { id: 2, name: 'Bob', active: false }
  ];

  // Push records and create table if missing
  await client.push('school.class.students', originalStudents, {
    createIfMissing: true,
    dedupeOnAppend: true,
    primaryKeyColumns: ['id']
  });

  // Push same data again — no changes applied
  await client.push('school.class.students', originalStudents, {
    dedupeOnAppend: true,
    primaryKeyColumns: ['id']
  });

  const updatedStudents = [
    { id: 1, name: 'Alice', active: false },
    { id: 2, name: 'Bob', active: false },
    { id: 3, name: 'Charles', active: false }
  ];

  // Update existing records, append new ones
  await client.push('school.class.students', updatedStudents, {
    dedupeOnAppend: true,
    primaryKeyColumns: ['id']
  });

  // Overwrite table with original data
  await client.push('school.class.students', originalStudents, {
    createIfMissing: true,
    replaceIfExists: true
  });

  const rows = await client.execute(
    'SELECT * FROM school.class.students WHERE active = $1',
    [true]
  );

  console.table(rows);
}

main().catch(console.error);

CommonJS Usage

const { Birkini } = require('@birkini/js-sdk');

async function main() {
  const client = new Birkini('ACCESSKEY:SECRET:USERNAME');
  await client.login();

  const originalStudents = [
    { id: 1, name: 'Alice', active: true },
    { id: 2, name: 'Bob', active: false }
  ];

  await client.push('school.class.students', originalStudents, {
    createIfMissing: true,
    dedupeOnAppend: true,
    primaryKeyColumns: ['id']
  });

  await client.push('school.class.students', originalStudents, {
    dedupeOnAppend: true,
    primaryKeyColumns: ['id']
  });

  const updatedStudents = [
    { id: 1, name: 'Alice', active: false },
    { id: 2, name: 'Bob', active: false },
    { id: 3, name: 'Charles', active: false }
  ];

  await client.push('school.class.students', updatedStudents, {
    dedupeOnAppend: true,
    primaryKeyColumns: ['id']
  });

  await client.push('school.class.students', originalStudents, {
    createIfMissing: true,
    replaceIfExists: true
  });

  const rows = await client.execute(
    'SELECT * FROM school.class.students WHERE active = $1',
    [true]
  );

  console.table(rows);
}

main().catch(console.error);

Last updated