Skip to content

Client-side database synchronizing with backend (if online)

License

Notifications You must be signed in to change notification settings

xpectme/synceddb

Repository files navigation

Synceddb

 

Synceddb

Github top language Github language count Repository size License


About   |   Technologies   |   Requirements   |   Getting started   |   License   |   Author


About

Client-side CRUD operations between indexedDB and a server.

Technologies

The following tools were used in this project:

  • idbx - an indexedDB wrapper

Getting started

import * as idbx from "https://deno.land/x/idbx/main.ts";
import { SyncedDB } from "https://deno.land/x/synceddb/main.ts";

// create a database
const dbreq = idbx.open('my-database', 1);

// create a store
dbreq.upgrade((event) => {
  const target = event.target as IDBOpenDBRequest;
  const db = target.result;
  SyncedDB.createStore(db, "mystore");
});

// wait for DB to initialize
const db = await dbreq.ready;

// create a synceddb instance
const syncdb = new SyncedDB(db, "mystore", {
keyName: "id",
  // Default Settings:
  
  // url: location.origin,
  // autoSync: false,
  // createPath: "/api/create",
  // readPath: "/api/read",
  // updatePath: "/api/update",
  // deletePath: "/api/delete",
  // readAllPath: "/api/read_all",
  // syncPath: "/api/sync",
});

const result = await syncdb.create({
  title: "Awesome!",
  description: "Probably a reinvention of the wheel ;-P"
});
// case 1 (online): writes entry into the indexedDB store and send the entry to the server
//                  sync_action: "none", sync_status: "synced"
// case 2 (offline): writes entry into the indexedDB store and creates a temporary ID
//                  sync_action: "create", sync_status: "unsynced"

License

This project is under license from MIT. For more details, see the LICENSE file.

Made by Mario Stöcklein

 

Back to top

About

Client-side database synchronizing with backend (if online)

Resources

License

Stars

Watchers

Forks

Packages

No packages published