hedera-db
v0.1.4
Published
Relational database built on top of Hedera Hashgraph.
Downloads
12
Readme
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