1.2.8 • Published 2 years ago

tobsdb v1.2.8

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

TobsDB NodeJS client

This is the official TobsDB NodeJS client.

Usage

import TobsDB from "tobsdb";

const db = new TobsDB("ws://localhost:7085", "db_name", {
  schema_path: "path/to/schema.tdb",
  username: "user",
  password: "password",
  log: true,
});
await db.connect();

const res = db.create("table_name", { hello: "world" });

Typescript Support

This is an example TobsDB schema:

// schema.tdb

$TABLE table_name {
    id      Int     key(primary)
    hello   String  default("world")
}

$TABLE example {
    id      Int     key(primary)
    world   String  unique(true)
    nested  Vector  vector(String, 2) optional(true)
}

The Typescript schema declaration for the above can be written as:

// index.ts
import TobsDB, { PrimaryKey, Unique, Default } from "tobsdb";

// schema declaration that translates to schema passed to the server
type Schema = {
  table_name: {
    id: PrimaryKey<number>;
    hello: Default<string>;
  };

  example: {
    id: PrimaryKey<number>;
    world: Unique<string>;
    nested?: string[][];
  };
};

const db = new TobsDB<Schema>(
                   // ^ schema type argument gives strict type inference
  "ws://localhost:7085",
  "db_name",
  {
    schema_path: "path/to/schema.tdb",
    username: "user",
    password: "password",
    log: true,
  },
);
await db.connect();

db.create(
  "table_name",
  // ^? "table_name" | "example"
  { hello: 2 }, // (???) typescript: Type 'number' is not assignable to type 'string'. [2322]
  // ^? { hello?: string, id?: number }
); 

In the above, the hello field is optional in create because we tell typescript it has a fallback default value. And the id is optional because TobsDB manages primary keys for you.

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.0

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.10

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago