0.1.4 • Published 10 months ago

hedera-db v0.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Hedera Database

The Hedera Database is a package that provides a simple interface to use the Hedera File Service as a database. It is built on top of the Hedera SDK, SQLite, and Prisma ORM.

How does it work?

This package "push" and "pull" the database content to and from a Hedera File. The database content is stored in a SQLite database file. The package provides a simple interface to interact with the database.

The main class HederaDb encapsulates and provides a prisma client instance to interact with the database using the features of the Prisma ORM, particularly it's intuitive query API.

Some diagrams illustrating the processes are provided in the diagrams folder of the repository.

Set up prisma client

No need to install prisma since it is already included in hedera-db package. Initialize it directly with the sqlite provider (hedera-db only supports sqlite).

npx prisma init --datasource-provider sqlite

Add the database schema to schema.prisma file.

Example schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
}

Make sure that the following env variables are set in a .env file:

DATABASE_FILE="prisma/hedera.db"
DATABASE_URL="file:hedera.db"
HEDARE_FILE_ID="0.0.xxxx"

If you don't have a file dedicated to the database, you can create one by running the following command:

??????????
npx prisma generate
0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago