Skip to content

functionalfoundry/query-engine

Repository files navigation

workflo/query-engine

Clojars Project Build Status

API docs

The workflo/query-engine allows to execute Om Next queries against different data layers, including:

Usage (DataScript)

(require '[clojure.spec.alpha :as s]
         '[workflo.macros.entity :refer [defentity registered-entities]]
         '[workflo.macros.entity.datascript :refer [entity-schema]]
         '[workflo.macros.specs.types :as types]
         '[workflo.query-engine.core :as query-engine]
         '[workflo.query-engine.data-layer.datascript-no-authorization :as dl])


;; Define a user entity with workflo/macros

(s/def :user/name ::types/string)
(s/def :user/email ::types/string)

(defentity user
  (spec
    (s/keys :req [:db/id
                  :user/name
                  :user/email])))


;; Create a DataScript schema

(def schema (->> (registered-entities)
                 (vals)
                 (map entity-schema)
                 (apply merge)))


;; Create a DataScript database

(def conn (ds/create-conn schema)


;; ... Populate the database with users ...


;; Run a query against the database, fetch all users
;; with their IDs and names

(query-engine/query [{:users [:db/id :user/name]}]
                    (dl/data-layer)
                    {:db @conn})

;; -> #{{:db/id 1 :user/name "John"}
;;      {:db/id 2 :usder/name "Linda"}}

Testing

  1. Install boot
  2. Clone this repository
  3. Run the tests:
    • boot test to run tests once
    • boot watch test to run tests continuously on changes

License

workflo/query-engine is copyright (C) 2016-2017 Workflo, Inc.

Licensed under the MIT License.

For more information see the LICENSE file.

About

Engine to run Om Next queries against different data layers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages