Skip to content

avelino/cljs-google-datastore

Repository files navigation

Google Cloud Datastore

Interoperability @google-cloud/datastore to cljs (ClojureScript)

Clojars Project

Installation

Add package dependencie in project.clj:

(defproject hello-world "1.0.0-SNAPSHOT"
  :description "FIXME: write"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [cljs-google-datastore "1.0.0"]])

Download dependencies:

lein deps

Example

(ns core
  (:require [cljs-google-datastore.core :as datastore]))

(defn- main []
  (let [ds (datastore/datastore)
        data {:created (.toJSON (new js/Date))
              :name "Google Cloud Datastore by cljs"
              :url "https://github.com/avelino/cljs-google-datastore"}])

    ;; save data
    (-> (datastore/save ds "KEY-NAME" data)
        (.then (fn [r] (prn r))))

    ;; update data - key 123
    (-> (datastore/save ds "KEY-NAME" data :key 123)
        (.then (fn [r] (prn r))))

    ;; delete - key 123
    (-> (datastore/delete ds "KEY-NAME" 123)
        (.then (fn [r] (prn r))))
    
    ;; get records -- apply filters
    (-> (datastore/query ds
                         "KEY-NAME"
                         {:created [[">" (.toJSON (new js/Date "2020-04-03T00:00:00z"))]
                                    ["<" (.toJSON (new js/Date "2020-04-09T00:00:00z"))]]
                          :active true}
                         :group ["created"]
                         :order {:created {:descending false}}
                         :limit 10)
        (.then (fn [r] (println r)))))