• Stars
    star
    569
  • Rank 78,369 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GroundDB is a thin layer providing Meteor offline database and methods

ground:db

Build Status semantic-release

GroundDB is a fast and thin layer providing Meteor offline database - Taking cloud data to the ground.

Features

This version of GroundDB is a caching only storage - meaning it does not support resuming of method calls/cross tab updates etc. But it's faster and async supporting local storages like:

  • localstorage
  • indexeddb
  • websql * SQLite (on cordova)

It's using localforage with some minor modifications - hopefully we can use localForage via npm in the future

Notes about migration to GroundDB II

Usage

A pure offline collection

  foo = new Ground.Collection('test');

Ground.Collection is client-side only and depends on LocalCollection for now

Get documents and updates from a Meteor Mongo Collection via DDP

  foo = new Ground.Collection('test');

  foo.observeSource(bar.find());

  Meteor.setTimeout(() => {
    // Stop observing - keeping all documents as is
    foo.stopObserver();
  }, 1000);

Limiting the stored data

If you want to clean up the storage and eg. have it match the current subscription, now you can:

  foo.keep(bar.find());

This will discard all documents not in the subscribed data

Limit the data stored locally

  foo.keep(bar.find({}, { limit: 30 }));

This will discard all but 30 documents

Limit the data stored locall using multiple cursors

  foo.keep(bar.find({ type: 'a' }, { limit: 30 }), bar.find({ type: 'b' }, { limit: 30 }));

This will keep at max 60 documents 30 documents of each type "a"/"b"

Clear the storage

  foo.clear();

This will empty the in memory and the local storage

Need a near backwards compatible solution?

This example behaves much like the previous version of ground db regarding caching a Mongo.Collection - This class inforces a manual clean up. Calling removeLocalOnly() will keep only the documents in the Mongo.Collection.

GroundLegacy = {
  Collection: class GroundLegacy extends Ground.Collection {
    constructor(collection, options) {
      if (!(collection instanceof Mongo.Collection)) {
        throw new Error('GroundLegacy requires a Mongo.Collection');
      }
      if (options.cleanupLocalData !== false) {
        throw new Error('GroundLegacy requires cleanupLocalData to be false');
      }

      // Create an instance of ground db
      super(collection._name);

      this.mongoCollection = collection;

      collection.grounddb = this;

      // Observe on the whole collection
      this.observeSource(collection.find());

      // Store super
      collection.orgFind = collection.find;
      collection.orgFindOne = collection.findOne;

      // Overwrite collection finds using the grounded data
      collection.find = (...args) => {
        return this.find(...args);
      };

      collection.findOne = (...args) => {
        return this.findOne(...args);
      };
    }

    removeLocalOnly() {
      // Remove all documents not in current subscription
      this.keep(this.mongoCollection.orgFind());
    }
  },
};

More

Read about:

Contributions

Feel free to send issues, pull requests all is wellcome

Kind regards Morten

More Repositories

1

meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
JavaScript
1,439
star
2

Meteor-CollectionFS

Reactive file manager for Meteor
JavaScript
1,051
star
3

meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
JavaScript
1,024
star
4

meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
JavaScript
920
star
5

meteor-simple-schema

Meteor integration package for simpl-schema
JavaScript
920
star
6

meteor-collection-hooks

Meteor Collection Hooks
JavaScript
657
star
7

meteor-user-status

Track user connection state and inactivity in Meteor.
JavaScript
557
star
8

meteor-publish-composite

Meteor.publishComposite provides a flexible way to publish a set of related documents from various collections using a reactive join
JavaScript
553
star
9

raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
JavaScript
515
star
10

meteor-tabular

Reactive datatables for large or small datasets
JavaScript
363
star
11

meteor-autocomplete

Client/server autocompletion designed for Meteor's collections and reactivity.
CoffeeScript
350
star
12

meteor-scss

Node-sass wrapped to work with meteor.
JavaScript
311
star
13

meteor-partitioner

Transparently divide a single meteor app into several different instances shared between different groups of users.
CoffeeScript
152
star
14

meteor-timesync

NTP-style time synchronization between server and client, and facilities to use server time reactively in Meteor applications.
JavaScript
118
star
15

meteor-link-accounts

Meteor link account package. based on this PR https://github.com/meteor/meteor/pull/1133
JavaScript
116
star
16

mongo-collection-instances

πŸ—‚ Meteor package allowing Mongo Collection instance lookup by collection name
JavaScript
73
star
17

Meteor-EventEmitter

Client and server event emitter
JavaScript
72
star
18

meteor-postcss

PostCSS for Meteor
JavaScript
68
star
19

meteor-mocha

A Mocha test driver package for Meteor 1.3+. This package reports server AND client test results in the server console and can be used for running tests on a CI server or locally.
JavaScript
67
star
20

meteor-elastic-apm

Meteor Elastic APM integration
JavaScript
57
star
21

organization

Discussions on organization of the organization 🎩
41
star
22

meteor-schema-index

Control some MongoDB indexing with schema options
JavaScript
38
star
23

meteor-publication-collector

Test a Meteor publication by collecting its output.
JavaScript
33
star
24

meteor-collection-extensions

Safely and easily extend the (Meteor/Mongo).Collection constructor with custom functionality.
JavaScript
31
star
25

stratosphere

Meteor private package server
JavaScript
28
star
26

meteor-method-hooks

JavaScript
26
star
27

meteor-autoform-select2

Custom select2 input type for AutoForm
JavaScript
25
star
28

meteor-autoform-bs-datepicker

Custom "bootstrap-datepicker" input type for AutoForm
JavaScript
25
star
29

react-router-ssr

Simple isomorphic React SSR for Meteor with subscribed data re-hydration
JavaScript
24
star
30

denormalize

Simple denormalization for Meteor
JavaScript
20
star
31

meteor-autoform-bs-datetimepicker

Custom bootstrap-datetimepicker input type with timezone support for AutoForm
JavaScript
17
star
32

meteor-packages

Client for Meteor Package Server API
JavaScript
14
star
33

Packosphere

A Meteor package explorer for you, and if you are so inclined to help build it, by you.
TypeScript
13
star
34

meteor-schema-deny

Deny inserting or updating certain properties through schema options
JavaScript
12
star
35

check-npm-versions

Enforces "peer" npm dependencies in Meteor 1.3+ Atmosphere packages.
TypeScript
11
star
36

meteor-browser-tests

A helper package for Meteor test driver packages. Runs client tests in a headless browser.
JavaScript
11
star
37

template-package

Template package with CI and everything else to get started quickly with creating a new FOSS Meteor package.
JavaScript
10
star
38

meteor-stylus

A fork of meteor:stylus with mquandalle:stylus plugins
JavaScript
8
star
39

meteor-minifiers-autoprefix

JavaScript
6
star
40

meteor-autoform-bs-button-group-input

A Bootstrap button group theme for the "select-checkbox" and "select-radio" AutoForm input types
JavaScript
6
star
41

ground-minimax

Minimax is a thin layer for Meteor providing EJSON.minify and EJSON.maxify
JavaScript
6
star
42

meteor-typescript

Typescript compiler package
TypeScript
5
star
43

meteor-api-untethered

A collection of packages to make Meteor available to other environments.
JavaScript
5
star
44

awesome-meteor

Curated list of awesome Meteor.js things.
5
star
45

Meteor-EventState

DEPRECATED: Evented state
JavaScript
4
star
46

meteor-autoform-themes

Officially supported themes for aldeed:autoform
JavaScript
3
star
47

push

JavaScript
2
star