1.0.1 • Published 8 months ago

@embark.sh/node-sdk v1.0.1

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
8 months ago

Embark: Effortless Database Abstraction for Node.js

Embark revolutionizes data management by abstracting the intricacies of database operations. Designed specifically for Node.js, developers can effortlessly craft custom data types via EmbarkEntity and utilize streamlined CRUD functionalities. Data is neatly organized and isolated by API key partitions, ensuring security and simplicity.

Why Choose Embark?

  • Streamlined Database Management: Say goodbye to the complexities of traditional databases. With Embark, you get straightforward CRUD operations without the operational overhead.

  • Custom Types with Ease: Extend EmbarkEntity to craft bespoke data types tailored to your needs, ensuring data consistency and structural integrity.

  • Siloed Data Storage: Every API key acts as a unique partition, making sure your data remains isolated, organized, and safe.

Installation

npm install @embark.sh/node-sdk

Usage

Basic Usage

import Embark from "@embark.sh/node-sdk";

// Initialize Embark with your API key and preferred region
new Embark({
  apiKey: "your-unique-api-key",
  region: "atlanta",
});

// Define a custom type
export class User extends EmbarkEntity {
  public id: string;
  public email: string;
  public paid: boolean;

  constructor(data: { id: string; email: string; paid: boolean }) {
    super();
    this.id = data.id;
    this.email = data.email;
    this.paid = data.paid;
  }

  protected getData(): Record<string, any> {
    return {
      id: this.id,
      email: this.email,
      paid: this.paid,
    };
  }
}

// Use CRUD operations
const newUser = new User({
  id: "cus_123456789",
  email: "alice@example.com",
  paid: false,
});
await newUser.Save();

const fetchedUser = await EmbarkSearchUtility.Search(
  { id: newUser.id },
  User
);
console.log(fetchedUser);

await fetchedUser.Delete();