0.1.4 • Published 2 years ago

pinatastore v0.1.4

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
2 years ago

🦄 Pinatastore Hits

A simple module to store and retrieve simple JSON data from a decentralized databse. (Pinata IPFS) Pinatastore uses a structure similar to firebase and stores them in ipfs through Pinata. (Collections and Documents) Pinatastore is basically a wrapper on top of the pinata API to make it easier to work with JSON data.

Note: This project was made for educational puposes. But feel free to use it in your projects

Demo

Hosted - https://colorstore.vercel.app/

Repo - https://github.com/notnavindu/pinatastore-demo

Coming soon

  • Query by primary key

Use this if ...

  • Your data is not complex
  • Your project is not large scale
  • Your data doesn't need encryption
  • Your data can be publicly stored

Installation

npm install pinatastore

or

yarn add pinatastore

Setup

import { Pinatastore } from "pinatastore"
const db = new Pinatastore(API_KEY, API_SECRET)

You can get the API key and API secret from the Pinata dashboard.

Methods

db.add(collection, data [, primaryKeys] ➔ returns the autogenerated ID of the document

Adds data to a given collection. This will auto-generate a unique ID for the document

  • collection String
    • Name of the collection
  • data Object
    • A JS Object with data you want to store
  • primaryKeys
    • (Coming soon)

Example

db.add("users", {
    name: "John",
    age: 34
});

db.set(collection, document, data [, primaryKeys] ➔ returns the ipfs hash ID of the document

set() will create a new document or rewrite the existing document of the given ID with the provided data

  • collection String
    • Name of the collection
  • document String
    • Name of the document
  • data Object
    • A JS Object with data you want to store
  • primaryKeys
    • (Coming soon)

Example

db.set("cities", "london", {
    population: "8.982 million"
});

db.getDoc(collection, document) ➔ Returns the document data

Get data of the given document

  • collection String
    • Name of the collection
  • document String
    • Name of the document
db.getDoc("cities", "london");

// returns
// {
//  documentId: 'cities',
//  data: { population: '8.982 million' }
// }

db.getCollection(collection) ➔ Returns an array of documents

Get all the documents of a collection

  • collection String
    • Name of the collection
db.getCollection("users");

// returns
// [
//  {
//    documentId: 'c4422589-0153-43eb-926a-71e2576aa1ad',
//    data: { name: 'John', age: 34 }
//  },
//  {
//    documentId: '967b91f4-e5f4-46fc-a26c-fdb881f8ccaa',
//    data: { name: 'Anna', age: 23 }
//  }
]

db.getCollectionHashes(collection) ➔ Returns an array of ipfs hashes

Returns an array of the ipfs hashes of the documents. These can be used to retrieve data on the client side. This can be useful if you have a server with limited performance.

  • collection String
    • Name of the collection
db.getCollectionHashes("users");

// returns
// [
//   'QmNnThL8PzHBsY6uRYWgGheN2wxvfFt13uwunw8rrNvJhh',
//   'QmZ6pv1jNnmBaASYkKEXAAJG7cWu2zNrDxbf7geiHuJ9UE' 
// ]

Keep in mind that this was made entirely because I was bored so there might be bugs here and there. Please feel free to open issues or contribute to the project :)