Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.
/ ag-gun Public archive

An angular (ver >= 6.x) wrapper for Gun database

License

Notifications You must be signed in to change notification settings

ivkan/ag-gun

Repository files navigation

ag-Gun

Don't use me yet.

Angular 6+ wrapper for Gun, a realtime, distributed, offline-first, graph database engine. Support server-side rendering.

GUN is a small, easy, and fast data sync and storage system that runs everywhere JavaScript does. The aim of GUN is to let you focus on the data that needs to stored, loaded, and shared in your app without worrying about servers, network calls, databases, or tracking offline changes or concurrency conflicts.

Install

npm i ag-gun --save

API

The AgGun service is a wrapper around the native Gun API's:

  • .opt(options)
  • .get(key)
  • .put(data)
  • .set(data)
  • .back()
  • .map(callback)
  • .open()
  • .on()
  • .once()
  • .list() ( very similar to .on, except that it gives you an array with each update.

Usage

First, import the AgGunModule with options to your AppModule:

import { AgGunModule } from 'ag-gun';

@NgModule({
  imports: [ 
      AgGunModule.forRoot({
            peers: ['https://localhost:8080/gun']
          })
   ]
})
export class AppModule { }

After adding AgGun service to your component:

import { Component } from '@angular/core';
import { AgGun } from 'ag-gun';
import { Observable } from 'rxjs';

@Component({
  selector   : 'app-root',
  templateUrl: './app.component.html',
  styleUrls  : ['./app.component.scss']
})
export class AppComponent
{
  items$: Observable<any[]>;

  constructor(private agGun: AgGun)
  {
    this.items$ = this.agGun.get('schema').list();
  }
}