Giter Club home page Giter Club logo

datafire's Introduction

Datafire

Persist Datascript databases in Firebase's Firestore.

Supports offline usage, tab synchronization, and multi-user simultaneously. You can use Firestore Security Rules to limit access.

Usage

Clojars Project

:dependencies [[datascript "0.18.9"]
               [datascript-transit "0.3.0"]
               [datafire "0.1.1"]]
(ns app.quickstart
  (:require ["firebase/app" :as firebase]
            [datascript.core :as d]
            [datafire.core :as df]))

; Initialize the Firebase app with your configuration.
(defonce firebase-config #js { ... })
(defonce app (let [app (.initializeApp firebase firebase-config)
                  ; Enable offline persistence.
                   _ (.enablePersistence (.firestore app))]
               app))

; Create a Datascript connection.
(defonce conn (d/create-conn))

; Create a link between the Datascript connection and the "dbs/quickstart" Firestore document path.
(defonce link (df/create-link conn "dbs/quickstart"))

; Start listening to transactions on Firebase and applies them to the Datascript connection.
; Previous transactions will be loaded onto the Datascript connection.
(defonce _ (df/listen! link))

; Persist tx-data on the link.
; Returns a promise that resolves when the transaction hits the server.
; Since the promise won't resolve while offline, it's recommended that you never wait for it.
(df/transact! link [{:msg (str "Persisted on " (.toISOString (js/Date.)))}])

; Query data using the Datascript connection.
(d/q '[:find  ?m
       :where [?e :msg ?m]]
     @conn)
; #{[Persisted on 2020-01-09T15:54:02.065Z] 
;   [Persisted on 2020-01-09T15:54:20.310Z] 
;   [Persisted on 2020-01-09T15:55:23.964Z] 
;   ...}

datafire's People

Contributors

filipesilva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

datafire's Issues

Thanks! DataFire is great

Hey Filipe :). Thank you for making this. I've been threatening to build a DataScript<->Firebase adapter for some time and I learned quite a bit about DS and FS internals by reading your code.

If you are ever interested in pursuing a lazy, streaming version of DataScript that can be mounted on any general purpose key-value store (I've been playing with RocksDB as a backend), I've been exploring some ideas for what I believe are improvements to both Datomic and DataScript. Commercially, I believe there is a sizeable opportunity to build a hosted DataScript service that feels like Firebase but with streaming indices, query-budgeting and graph-based query capabilities. Then again, a horizontal graph interface like Roam may be a more natural route to market. Many graph probabilities to explore in the coming years :).

All the best
Petrus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.