Use Pinata (IPFS) as a simple datastore

Overview

🦄 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 :)

You might also like...

a Node.JS script to auto-import USB drives that are attached to a computer. Use it to turn your NAS into a smart photo / file importer.

File Vacuum 5000 ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ WARNING: This script is designed to manipulate files on both an external drive and another specif

Jan 10, 2022

graphql-codegen plugin to generate type-safe, easy-to use hooks for Flutter

graphql-codegen-flutter-artemis-hooks This is graphql-codegen plugin to generate type-safe, easy-to use Flutter artemis hooks. For further detail, see

Jan 2, 2023

⛰ "core" is the core component package of vodyani, providing easy-to-use methods and AOP implementations.

Vodyani core ⛰ "core" is the core component package of vodyani, providing easy-to-use methods and AOP implementations. Installation npm install @vodya

Oct 18, 2022

Cli created by shoulders to facilitate the development of Nest.js applications that use our seed!

Nest CLZ Your CLI by Shoulders to create a backend started with nest-seed Installation We will launch the application soon! Using npm: npm i -g nest-c

Mar 22, 2022

WASM-based implementation of Cloudflare's HTML Rewriter for use in Deno, browsers, etc.

HTML Rewriter WASM-based implementation of Cloudflare's HTML Rewriter for use in Deno, browsers, etc. It uses lol-html under the hood, the same implem

Dec 6, 2022

A WebAssembly build of the Tesseract OCR engine for use in the browser and Node

tesseract-wasm A WebAssembly build of the Tesseract OCR engine for use in the browser and Node. tesseract-wasm can detect and recognize text in docume

Dec 28, 2022

A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

Nov 29, 2022

Fast File is a quick and easy-to-use library to convert data sources to a variety of options.

Fast File is a quick and easy-to-use library to convert data sources to a variety of options.

Fast File Converter The Express.js's Fast File Converter Library Fast File Converter Library is a quick and easy-to-use library to convert data source

Nov 16, 2022

A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Jan 2, 2023
Owner
Navindu Amarakoon
2b || !(2b)
Navindu Amarakoon
A simple easy-to-use database, built for beginners.

ByteDatabase: Built for Beginners Table of Content Features Installation Changelog Quick Examples Contributors Features Persistent Storage: Data store

CloudTeam 9 Nov 20, 2022
An easy-to-use multi SQL dialect ORM tool for Node.js

Sequelize Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction s

Sequelize 27.3k Jan 4, 2023
A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

knex.js A SQL query builder that is flexible, portable, and fun to use! A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle

knex 16.9k Jan 4, 2023
Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.

Lovefield Lovefield is a relational database written in pure JavaScript. It provides SQL-like syntax and works cross-browser (currently supporting Chr

Google 6.8k Jan 3, 2023
Workshop to illustrate how to use GraphQL

?? Netflix Clone using Astra DB and GraphQL 50 minutes, Intermediate, Start Building A simple ReactJS Netflix homepage clone running on Astra DB that

DataStax Developers 606 Jan 4, 2023
A proposal to add modern, easy to use binary encoders to the web platform.

proposal-binary-encoding A proposal to add modern, easy to use binary encoders to the web platform. This is proposed as an addition to the HTML spec,

Luca Casonato 35 Nov 27, 2022
This API can be use to all developers to get location details of Sri Lanka 🇱🇰 including major cities, sub areas, districts and Provinces. ⛳️

Location Data API - Sri Lanka Table of Contents Introduction Technologies Implemantations Hosting Use Cases Getting Started Project Setup Contributing

Pasindu Senarathne 35 Jun 29, 2022
An easy-to-use discord bot including database, slash commands and context menus !

Discord Bot Template An easy-to-use discord bot using Discord.JS V13. Wiki Includes: Slash commands Database User commands and more in future Requirem

Gonz 108 Dec 28, 2022
Illustration of issues around use of top-level await in Vite apps

vite-top-level-await-repro Illustration of issues around use of top-level await in Vite apps: https://github.com/vitejs/vite/issues/5013 Top-level awa

Rich Harris 6 Apr 25, 2022
NodeDomainScrape - Use puppeteer to catch the data from domain.com.au

nodeDomainScrape 1 install node (https://nodejs.org/en/) and download the code; 2 run npm install in the terminal; 3 go to "https://www.domain.com.au/

null 1 Jan 2, 2022