Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tragedy-labs/sprite

Package Overview
Dependencies
Maintainers
0
Versions
7
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.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
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

FAQs

Package last updated on 07 Aug 2024

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc