Socket
Book a DemoInstallSign in
Socket

@tragedy-labs/sprite

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tragedy-labs/sprite

A TypeScript driver for ArcadeDB

0.1.6
latest
Source
npmnpm
Version published
Weekly downloads
2
-66.67%
Maintainers
2
Weekly downloads
 
Created
Source

Sprite

Test workflow badge

Sprite is a TypeScript driver for ArcadeDB.

Read the documentation, or see the examples below.

Installation

(Use whichever package manager you prefer)

<npm|pnpm|yarn|bun> <install|add> @tragedy-labs/sprite

Examples

SpriteServer

@import { SpriteServer } from '@tragedy-labs/sprite';

const server = new SpriteServer({
  username: 'aUser',
  password: 'aPassword',
  address: 'http://localhost:2480'
});

async function example() {

  const ready = await server.serverReady();
  console.log(ready);
  // true;

  try {
    const db = await server.createDatabase('aDatabase');
    console.log(db.name);
    // 'aDatabase'

    const result = await db.command(
      'sql',
      'CREATE document TYPE aType'
    );
    console.log(result);
    // [
    //   {
    //     operation: 'create document type',
    //     typeName: 'aType'
    //   }
    // ]

    // CRUD must be transactional
    // Parameterized commands are used to prevent
    // SQL injection, parameters are passed in an
    // object as the third argument
    db.transaction(async (trx) => {
      const doc = trx.crud(
        'sql',
        'INSERT INTO aType SET aProperty = :aValue',
        { aValue: 1 }
      );
    });
  } catch (error) {
    throw new Error('Could not create database', { cause: error });
  }
}

example();

SpriteDatabase

@import { SpriteDatabase } from '@tragedy-labs/sprite';
@import type {
  CreateDocumentType,
  InsertDocument,
  SelectFrom
} from '@tragedy-labs/sprite';

const db = new SpriteDatabase({
  username: 'aUser',
  password: 'aPassword',
  address: 'http://localhost:2480',
  databaseName: 'aDatabase'
});

type ExampleDoc = {
  aValue: string;
};

async function example() {
  try {
    const created = await db.command<CreateDocumentType>(
      'sql',
      'CREATE document TYPE aType'
    );
    console.log(created);
    // [
    //   {
    //     operation: 'create document type',
    //     type: 'aType'
    //   }
    // ]

    const schema = await db.getSchema();
    console.log(schema);
    // [...]

    // CRUD must be part of a transaction
    // Parameterized commands are used to prevent
    // SQL injection, parameters are passed in an
    // object as the third argument.
    db.transaction(async (trx) => {
      await trx.crud(
        'sql',
        'INSERT INTO aType SET aProperty = :aValue',
        { aValue: 1 }
      );
    });

    const docs = await db.query<SelectFrom<ExampleDoc>>(
      'sql',
      'SELECT * FROM aType'
    );
    console.log(docs);
    // [
    //   {
    //     aProperty: 'aValue'
    //   }
    // ]

  } catch (error) {
    throw new Error('An error occured...', { cause: error });
  }
}

example();

Keywords

typescript

FAQs

Package last updated on 22 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.