0.0.1 • Published 2 years ago

@jabberwocky-labs/ts-db v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

The home of Jabberwocky Labs' TypeScript community code. For now, this codebase will focus on our database product, however, this will be expanded to support additional Jabberwocky Labs products as well as non-product, open-sourced TypeScript projects.

⬇️ Install

Run the following command at the root of your project:

Yarn

yarn add @jabberwocky-labs/ts-db

NPM

npm install @jabberwocky-labs/ts-db

📘 Terminology

Space

A space can be thought of as an independent timeline of your databases records. Spaces reference shared locations for the used primitives allowing for non-duplicated values across spaces. The value My awesome string will only exist once across your spaces. However, in your usage of spaces, they operate as isolated environments. In the future, we will be adding extended functionality to allow for spaces to branch from, merge together, and stream to one another.

Example:

You may have both a production space and a development space to allow you to work locally without affecting production data. With this setup, you may periodically clone the production space over the development space so that you can safely test/build with your production data. Because the values of your space need not be cloned, just the architecture of it, this clone will happen in microseconds.

Class

A class is a means of classifying your data. Some example classes may be firstName, emailAddress, or phoneNumber.

Value

A value is a primitive type:

  • null
  • boolean
  • string
  • number
  • float

Item

An item is the unique combination of a class and value within a space. An item can have sub items which you interact with like you would record properties in other databases. The key difference here is that an item only exists once and using it as a property creates a relationship between data.

🔧 Setup

All requests are run through the JabberwockyDBClient

import { JabberwockyDBClient } from '@jabberwocky-labs/ts-db';

const client = new JabberwockyDBClient();

You can authenticate by directly passing your token:

const client = new JabberwockyDBClient({ token: 'xxxxxxx' });

However, the recommended method is to set the JW_TOKEN environment variable using a tool like dotenv or via node directly:

JW_TOKEN=xxxxxxx node index.js

🚀 Usage

Account

Initiate Account Client

const account = client.account(123456);

Space

Initiate Space Client

const productionSpace = account.space('production');

Check Existence

const doesExist = await productionSpace.exists();

Ensure Not Existing

await productionSpace.ensureMissing();

Class

Initiate Class Client

const emailClass = productionSpace.class('email');

Check Existence

const doesExist = await emailClass.exists();

Ensure Not Existing

await emailClass.ensureMissing();

Item

Initiate Item Client

const zachsEmails = emailClass.item('zach@jabberwockylabs.com');

Check Existence

const doesExist = await zachsEmails.exists();

Ensure Not Existing

await zachsEmails.ensureMissing();