All Projects → sosuisen → git-documentdb

sosuisen / git-documentdb

Licence: MPL-2.0 License
Offline-first Database that Syncs with Git

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to git-documentdb

Kinto.js
An Offline-First JavaScript Client for Kinto.
Stars: ✭ 268 (+1240%)
Mutual labels:  sync, offline-first
Remotestorage.js
⬡ JavaScript client library for integrating remoteStorage in apps
Stars: ✭ 2,155 (+10675%)
Mutual labels:  sync, offline-first
client-side-databases
An implementation of the exact same app in Firestore, AWS Datastore, PouchDB, RxDB and WatermelonDB
Stars: ✭ 787 (+3835%)
Mutual labels:  sync, offline-first
reddit-pocket-sync
No description or website provided.
Stars: ✭ 37 (+85%)
Mutual labels:  sync
platyplus
Low-code, offline-first apps with Hasura
Stars: ✭ 22 (+10%)
Mutual labels:  offline-first
jekyll-pwa-workbox
A Jekyll plugin using Workbox to make your PWA / Website available offline.
Stars: ✭ 22 (+10%)
Mutual labels:  offline-first
CosmosDB
PowerShell Module for working with Azure Cosmos DB databases, collections, documents, attachments, offers, users, permissions, triggers, stored procedures and user defined functions.
Stars: ✭ 104 (+420%)
Mutual labels:  documentdb
contentz
Create Content, Get a Highly Optimized Website
Stars: ✭ 57 (+185%)
Mutual labels:  offline-first
quiz-app
🏆 QuizApp is a free and open-source quiz application that lets you play fully customized quizzes right in the browser.
Stars: ✭ 97 (+385%)
Mutual labels:  offline-first
state
A Redux-based state container for local-first software, offering seamless synchronization using Automerge CRDTs. (Formerly known as 🐟 Cevitxe).
Stars: ✭ 126 (+530%)
Mutual labels:  offline-first
atom-package-sync
Synchronize your atom packages and settings easily
Stars: ✭ 22 (+10%)
Mutual labels:  sync
Teller-Android
Android library that manages your app's cached data with ease.
Stars: ✭ 13 (-35%)
Mutual labels:  offline-first
terraform-aws-documentdb-cluster
Terraform module to provision a DocumentDB cluster on AWS
Stars: ✭ 32 (+60%)
Mutual labels:  documentdb
KoHighlights
KOHighlights is a utility for viewing KOReader's highlights and/or export them to simple text, csv or html files.
Stars: ✭ 62 (+210%)
Mutual labels:  sync
tsdav
WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser
Stars: ✭ 33 (+65%)
Mutual labels:  sync
hstdb
Better history management for zsh. Based on ideas from https://github.com/larkery/zsh-histdb.
Stars: ✭ 25 (+25%)
Mutual labels:  sync
NYTimes-Compose
An offline-first application in Jetpack Compose with MVVM architecture, representing a minimalistic implementation of Top Stories API.
Stars: ✭ 98 (+390%)
Mutual labels:  offline-first
Cosmos.Identity
A Cosmos storage provider for ASP.NET Core Identity.
Stars: ✭ 26 (+30%)
Mutual labels:  documentdb
TogetherStream
A social and synchronized streaming experience
Stars: ✭ 16 (-20%)
Mutual labels:  sync
uzual-mobile
Feed your brains with habits for a better mood
Stars: ✭ 67 (+235%)
Mutual labels:  offline-first

GitDocumentDB

GitDocumentDB

npm version License: MPL 2.0 Coverage Status

TypeScript Ready Offline-first Database that Syncs with Git

Use GitDocumentDB to ...

🔩 Develop offline-capable applications using Git.

📗 Manage JSON documents in Git repository by CRUD and collection APIs.

🚀 Synchronize automatically with remote repositories.

     (No need to resolve conflicts manually!)

🔄 Integrate CI/CD pipelines through GitHub.

🐪 Get revision history of a document.

(More...)

API

https://gitddb.com/docs/api/git-documentdb.gitdocumentdb

Usage

Getting started

Prerequisite

Node.js 12 or later

Installation

npm i git-documentdb

Import

import { GitDocumentDB } from 'git-documentdb';

const gitDDB = new GitDocumentDB({
  db_name: 'db01', // Git working directory
});

Basic CRUD

  /**
   * Open a database
   */
  await gitDDB.open(); 


  /**
   * Create a document
   */ 
  await gitDDB.put({ _id: 'nara', flower: 'cherry blossoms', season: 'spring' });

  console.log(`$ gitDDB.put({ flower: 'cherry blossoms' ... }) # Create`);
  console.log(await gitDDB.get('nara')); 
  // log: { _id: 'nara', flower: 'cherry blossoms', season: 'spring' }

  /**
   * Update a document if it exists.
   */
  await gitDDB.put({ _id: 'nara', flower: 'double cherry blossoms', season: 'spring' }); 

  /**
   * Read a document
   */
  const doc = await gitDDB.get('nara');

  console.log(`\n$ gitDDB.put({ flower: 'double cherry blossoms' ... }) # Update`);
  console.log(doc);
  // log: { flower: 'double cherry blossoms', season: 'spring', _id: 'nara' }

  /**
   * Delete a document
   */
  await gitDDB.delete('nara');

  console.log(`\n$ gitDDB.delete('nara') # Delete`);
  console.log(await gitDDB.get('nara'));
  // log: undefined
  
  /**
   * Use an auto-generated _id
   */
   const appleResult = await gitDDB.put({ name: 'apple' }); // _id does not exist.
   const apple = await gitDDB.get(appleResult._id);
   console.log(`\n_id of the JSON document is automatically generated`);
   console.log(apple);
   // log: { name: 'apple', _id: 'XXXXXXXXXXXXXXXXXXXXXXXXXX' }

Revisions

  /**
   * Revisions 
   * 
   * getOldRevision(id, 2) returns a document two revisions older than the latest.
   * 
   * #0 (latest): undefined (deleted)
   * #1: 'double cherry blossoms'
   * #2: 'cherry blossoms'
   */
  const oldDoc = await gitDDB.getOldRevision('nara', 2); 

  console.log(`\n$ gitDDB.get('nara', 2) # Get a document two revisions older than the latest.`);
  console.log(oldDoc);
  // log: { _id: 'nara', flower: 'cherry blossoms', season: 'spring' }

Synchronization

  await gitDDB.sync({
    live: true,
    remote_url: 'https://github.com/enter_your_accunt_name/git-documentdb-example.git',
    connection: { type: 'github', personal_access_token: 'Enter your personal access token with checked [repo]' },
  });

(You can find more examples in examples/src/sync.ts)

Prefix search

 /**
    Create documents under sub-directories

    git-documentdb
    └── db01
        ├── nara
        │   ├── nara_park.json
        │   └── tsukigase.json
        └── yoshino
            └── mt_yoshino.json

  */
  await gitDDB.put({ _id: 'nara/nara_park', flower: 'double cherry blossoms' });
  await gitDDB.put({ _id: 'nara/tsukigase', flower: 'Japanese apricot' });
  await gitDDB.put({ _id: 'yoshino/mt_yoshino', flower: 'cherry blossoms' });

  // Read
  const flowerInYoshino = await gitDDB.get('yoshino/mt_yoshino');
  console.log(flowerInYoshino);
  // log:: { flower: 'cherry blossoms', _id: 'yoshino/mt_yoshino' }

  /**
   * Prefix search
   * 
   * Read all the documents whose IDs start with the prefix.
   */ 
  const flowersInNara = await gitDDB.find({ prefix: 'nara/' });
  console.log(flowersInNara);
  /* log:
    [
      { flower: 'double cherry blossoms', _id: 'nara/nara_park' },
      { flower: 'Japanese apricot', _id: 'nara/tsukigase' }
    ]
  */
 
  // destroy() closes DB and removes
  // both the Git repository and the working directory.
  await gitDDB.destroy();

Collections

  // Try sub-directories again by another way.
  await gitDDB.open();
  // Use Collection Class to make them easier.
  const nara = gitDDB.collection('nara');
  const yoshino = gitDDB.collection('yoshino');
  await nara.put({ _id: 'nara_park', flower: 'double cherry blossoms' });
  await nara.put({ _id: 'tsukigase', flower: 'Japanese apricot' });
  await yoshino.put({ _id: 'mt_yoshino', flower: 'cherry blossoms' });

  // Read
  const flowerInYoshinoCollection = await yoshino.get('mt_yoshino');
  console.log(flowerInYoshinoCollection);
  // { flower: 'cherry blossoms', _id: 'mt_yoshino' }

  // Read all the documents in nara collection
  const flowersInNaraCollection = await nara.find();
  console.log(flowersInNaraCollection);
  /* log: 
    [
      { flower: 'double cherry blossoms', _id: 'nara_park' },
      { flower: 'Japanese apricot', _id: 'tsukigase' }
    ]
  */  
  await gitDDB.close();

(You can find more examples in examples/src/collection.ts)

Examples:

See examples directory.

$ npm run build
$ cd examples
$ npm i
$ npm start
$ npm run sync
$ npm run collection

Continuous Deployment (CD) using GitDocumentDB

https://github.com/sosuisen/sosuisen-my-inventory-gatsby

App using GitDocumentDB

https://github.com/sosuisen/inventory-manager

Roadmap

  • v0.1 Basic CRUD 🐾

  • v0.2 Group and Search 🐾

    • Collections 🐾
    • Prefix search 🐾
  • v0.3 Synchronization 🐾

    • Synchronization with GitHub 🐾
    • Revisions 🐾
    • Automated conflict resolution 🐾
    • Automated JSON diff and patch 🐾
    • Automated combining of inconsistent repositories 🐾
  • v0.4 Work on both Node.js and browser

    • API renewal to manage any data types 🐾
    • Remove native module (NodeGit) from default install 🐾
    • Add plugin system for remote connection (isomorphic-git or NodeGit) 🐾
    • Connect with SSH key pair 🐾
    • Connect to GitHub with OAuth 🐕(Next)
    • Work on browser
  • Until v1.0

    • Sync any data types
    • Replication
    • Grep
    • Transaction (bulk)
    • Tag
    • Indexed Search
    • GitLab and Bitbucket
    • Push server
    • Migration

(https://github.com/sosuisen/git-documentdb/projects/2)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].