RONIN Client for TypeScript

3.29.10 · active · verified Wed Apr 22

The `blade-client` package provides a robust and type-safe client for accessing and querying data from your RONIN database. Currently at version 3.29.10, this library is designed for ease of use and integrates seamlessly into modern JavaScript and TypeScript projects, including those targeting edge and serverless environments. While an explicit release cadence isn't stated, the frequent version updates suggest active development and maintenance. Its key differentiator is its direct, strongly-typed access to RONIN databases, abstracting complex database interactions into a developer-friendly API that includes ORM-like query, insert, and update operations. It's built to be a reliable solution for applications requiring efficient and secure data retrieval and manipulation from RONIN backends.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the RONIN client, perform basic `SELECT` queries, `INSERT` new records, and `UPDATE` existing ones. It includes error handling and assumes an environment variable for the API key.

import { RONINClient } from 'blade-client';

async function main() {
  // Initialize the RONINClient with your API key and optionally an endpoint.
  // It's recommended to use environment variables for sensitive information.
  const roninClient = new RONINClient({
    apiKey: process.env.RONIN_API_KEY ?? 'your-development-api-key',
    // endpoint: process.env.RONIN_ENDPOINT ?? 'https://api.ronin.example.com/v1' // Optional: if your RONIN instance has a custom endpoint
  });

  try {
    console.log('Attempting to fetch data from RONIN database...');

    // Example 1: Fetch all entries from a 'users' collection/table
    const allUsers = await roninClient.query<{ id: string; name: string; email: string }[]>(
      `SELECT id, name, email FROM users`
    );
    console.log('Fetched users:', allUsers.slice(0, 3)); // Log first 3 users for brevity

    // Example 2: Insert a new record into a 'logs' collection
    const newLogEntry = { timestamp: new Date().toISOString(), message: 'Application startup', level: 'INFO' };
    const insertResult = await roninClient.insert('logs', newLogEntry);
    console.log('Inserted new log entry with ID:', insertResult.id);

    // Example 3: Update an existing record in 'products' with a specific ID
    const productIdToUpdate = 'some-product-uuid'; // Replace with an actual product ID
    const updateResult = await roninClient.update('products', { price: 29.99 }, { id: productIdToUpdate });
    console.log(`Updated product ${productIdToUpdate}:`, updateResult);

  } catch (error) {
    console.error('An error occurred during RONIN operation:');
    if (error instanceof Error) {
      console.error('Error message:', error.message);
      console.error('Error stack:', error.stack);
    } else {
      console.error(error);
    }
  }
}

main().catch(error => {
  console.error('Unhandled error in main function:', error);
  process.exit(1);
});

view raw JSON →