npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

scoopabase

v1.0.0

Published

A Firestore-Style Databse... Offline! Live Updates on Document change.

Downloads

221

Readme

ScoopaBase

A Firestore-Style Databse... Offline! Live Updates on Document change.

ScoopaBase gives you an offline database with simplicity & power of Firestore, And It stores data in user's browser - IndexDB.

ScoopaBase is build on top of LocalForage. RxJs. Typescript.

Contents

Getting Started

Installation

npm install scoopabase --save
import { ScoopaBase } from 'scoopabase'

let db = new ScoopaBase('db')

Quick Start

Getting started by adding a new document into a collection. Just call collection method on db object and pass a collection-name as an argument. then specify a document you want to add with th add method.

db.collection('users').add({
  id: 1,
  name: 'imhpdev',
  age: 150
}, 'key')

Now your document has been added to the collection. Now let's retrive it.

db
  .collection('users')
  .get('key')
  .then((value) => {...});

// { id: 2, name: 'Paul', age: 34 }

Adding Data

Add a document to a Collection

Add a document without a key

db.collection('users').add({
  id: 1,
  name: 'imhpdev',
  age: 150
})

Add a document with user-defined key

db.collection('users').add({
  id: 1,
  name: 'imhpdev',
  age: 150
}, 'key')

Add multiple documents at once in a Collection.

db.collection('users').addDocuments([
  {...},
  {...},
  {...},
  {...},
  {...},
  {...}
], 'key')

Overwrite a document

this.db.
  collection('users').
  update({ newKey: 'ohoooo!' },
   'key')

Getting Data

Get a Collection Observable

Get all documents Observable from a collection with it's associate key.

db.collection('users').documents$.subscribe(data => {...})

//  [
//    { id: 1, name: 'Bill', age: 47 },
//    { id: 2, name: 'Paul', age: 34 }
//  ]

Get a Document Observable

Get an individual document from a collection

db
  .collection('users')
  .document$('key')
  .subscribe((value) => {...});

// { id: 2, name: 'Paul', age: 34 }

Get a Document Promise

Get an individual document from a collection

db
  .collection('users')
  .get('key')
  .then((value) => {...});

// { id: 2, name: 'Paul', age: 34 }

Advanced Usage with Operators

ScoopaBase provides some operators to work with collection observable.

OrderBy

orderby operator will allow to order a collection on any key value.

db
  .collection('user')
  .documents$
  .pipe(orderby('age'))
  .subscribe(() => {...})

//  [
//    { id: 2, name: 'Paul', age: 34 }
//    { id: 1, name: 'Bill', age: 47 },
//  ]

orderby will work on even nested key. If the nested key does not exist in a docment then it will filter-out those documents and it will be not included in a filtered list.

db
  .collection('user')
  .documents$
  .pipe(orderby('name.fname'))
  .subscribe(() => {...})

//  [
//    { id: 2, name: { fname: 'Paul', lname: 'Costa'}, age: 34 }
//    { id: 1, name: { fname: 'Zendeya', lname: 'Bouch'}, age: 47 },
//  ]  

Limit

limit operator will limit the number of documents comming from a Collection.

db
  .collection('user')
  .documents$
  .pipe(limit(1))
  .subscribe(() => {...})

//  [
//    { id: 1, name: { fname: 'Zendeya', lname: 'Bouch'}, age: 47 },
//  ]  

scoopaFilter

scoopaFilter operater will filter-out documents in a collection based on a condition. This operator allows to filter data based on your filter function. scoopaFilter requires a key on which a filter is going to apply it works on nested key as well. And a filter function which will getting applied on a key that mentioned in first argument.

db
  .collection('user')
  .documents$
  .pipe(scoopaFilter('age', (age) => age > 40))
  .subscribe(() => {...})

//  [
//    { id: 1, name: { fname: 'Zendeya', lname: 'Bouch'}, age: 47 },
//  ]  

Where

where operater will filter-out documents in a collection based on a condition. This operator allows to query data on based on operator it supports. where queries data based on <, <=, ==, >=, >, includes, contains.

<, <=, ==, >=, > works on string, number, etc... types.

db
  .collection('user')
  .documents$
  .pipe(where('name.age','>',40))
  .subscribe(() => {...})

//  [
//    { id: 1, name: { fname: 'Zendeya', lname: 'Bouch'}, age: 47 },
//  ]  

contains works on Array types.

db
  .collection('user')
  .documents$
  .pipe(where('colors','contains',red))
  .subscribe(() => {...})

// Collection Data
//  [
//    { id: 1, colors: ['blue', 'green', 'red'], type: 'type A' },
//    { id: 2, colors: ['blue', 'green'], type: 'type B' },
//    { id: 3, colors: ['blue', ,'red'], type: 'type C' },
//  ] 

// Collection Data After Where Applied
//  [
//    { id: 1, colors: ['blue', 'green', 'red'], type: 'type A' },
//    { id: 3, colors: ['blue', ,'red'], type: 'type C' },
//  ] 

StartAfter

startAfter operator will emit later documents from a document key specified in it's argument. This operator combines with limit operator create pagination effect on a collection.

db
  .collection('user')
  .documents$
  .pipe(
    startAfter('documentKey')
    limit(1)
  )
  .subscribe(() => {...})

//  [
//    { id: 1, name: { fname: 'Zendeya', lname: 'Bouch'}, age: 47 },
//  ]  

StartBefore

startBefore operator will emit before documents from a document key specified in it's argument. This operator combines with limit operator create pagination effect on a collection.

db
  .collection('user')
  .documents$
  .pipe(
    startBefore('documentKey')
    limit(1)
  )
  .subscribe(() => {...})

//  [
//    { id: 1, name: { fname: 'Zendeya', lname: 'Bouch'}, age: 47 },
//  ]  

Deleting Data, Collection and Database

Delete a document

Delete a document from a collection.

db.collection('users').deleteDocument('key').then(() => {...})

Clear Collection

Delete all documents from a collection.

db.collection('users').clearAll().then(() => {...})

Delete a collection

Delete a collection and all documents contained in it.

db.deleteCollection('collection-name')

Delete Database

Delete whole database and it's all collection.

db.deleteDatabase()