GithubHelp home page GithubHelp logo

typeetfunc / datascript-mori Goto Github PK

View Code? Open in Web Editor NEW
37.0 5.0 6.0 270 KB

Package for union datascript and mori

Home Page: https://www.npmjs.com/package/datascript-mori

License: Eclipse Public License 1.0

Clojure 30.42% HTML 9.81% JavaScript 58.57% Shell 1.20%

datascript-mori's Introduction

datascript-mori

Wrapper for datascript interplay with mori

Why?

Datascript is greatful project - an immutable in-memory database and Datalog query engine in Clojure and ClojureScript. It is very useful for managing very big and complex application state in frontend application.

Datascript is written in ClojureScript. Also Datascript designed for using from ClojureScript, but it has JS dedicated API. However usage Datascript from JS has problems:

  • functions for quering - q, pull, pull_many, index_range etc. - convert result of query into JS data structures(Array, Object). JS data structures is mutable data strutures with very bad API. Also when you use mutable data structures in React app, you can not use "pure render" optimisations. See more cases for immutability. datascript-mori open access for all Datascript API and some helpers.
  • Datascript includes ClojureScript Runtime. It is very big amount of code includes extensive set of immutable data structures. However it is useless without mori. But when you're importing mori and Datascript, the size of your application will grow twice(because mori and Datascript are two separate packages for Javascript). datascript-mori join their codebase.

Setup

  • (Recommended) Install from NPM
npm install datascript-mori

Usage

  • (Recommended) Using EcmaScript 2015 modules:
import {
    datascript, // This is contain datascript object
    mori,       // This is contain mori object
    helpers     // This is contain helpers for conversions from CLJS
} from 'datascript-mori';

const {
    core, // This is pure DataScript CLJS API without any conversions
    js    // This is DataScript JS API
} = datascript;
  • Using CommonJS modules:
var datascript_mori = require('datascript-mori');

var mori = datascript_mori.mori;
var datascript_js = datascript_mori.datascript.js;
var datascript_core = datascript_mori.datascript.core;
var helpers = datascript_mori.helpers;
  • (Not recommended) Using tag <script> in Browser:
<script src="datascript-mori.js">
   var mori = datascript_mori.mori;
   var datascript_js = datascript_mori.datascript.js;
   var datascript_core = datascript_mori.datascript.core;
   var helpers = datascript_mori.helpers;
</script>

API Overview

  • datascript_mori.datascript.core - is a CLJS DataScript API. All functions accept CLJS data structures and return back CLJS data structures(i.e mori values). All names of these functions converts("munging") with symbols allowed in JS for function name. See mapping list.
  • datascript_mori.datascript.js - is a JS DataScript API
  • mori - is a mori object
  • helpers - is a helpers functions for convert JS data structures to CLJS data structures and CLJS data structures to JS data structures. Also helpers contains functions for parsing Datalog queries - parse_query and parse_pull.

Examples

Roadmap

  • Investigate Posh and include to datascript-mori support tx-pattern

Related projects

datascript-mori's People

Contributors

ashnur 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

Watchers

 avatar  avatar  avatar  avatar  avatar

datascript-mori's Issues

Up to date versions?

Hello. I'm curious if this library is still in use - the versions of both Clojure and Datascript are behind. I try to trivial upgrade and hit errors... before digging in, if it turns out there is an upgrade sitting out there that just hasn't been pushed yet, I would be pleased to obtain it. :-)

Include rx-datascript?

This is a (small?) feature request.

Currently a compelling benefit of datascript-mori is that it includes a single copy of the CLJS runtime, and the two libraries you are most likely to need while working with Datascript from JavaScript.

The feature request is to include other adjacent, small (and therefore pretty painless to people not using them) libraries, to further expand the set of related tools trivially loadable for use in a JavaScript project.

How about including rx-datascript? It's essentially one source file of 108 lines.

https://github.com/typeetfunc/rx-datascript

(Obviously there are diminishing returns past a very small number of related libraries. Someone needs more than a small handful probably has to make their own bundle.)

Documentation and usage

I would love to see the README expanded with links to your new test examples and some more explanations for when/how to use this library and the rationale behind it.

Also if you could, please include some info on how you see it used in a real life (React) app ;)

Thanks :)

PS: Also not sure about how to use the babel-plugin you mentioned for a real world use case. Perhaps create a datascript-mori-react-app example in a separate repo?

Can't build the the npm module

Hi,

I'm trying to update my clone of datascript-mori to more recent versions of datascript and cljs. However, I'm having issue building the JS even before updating the version numbers.

I get the error:

  var db = d.empty_db(scheme);
             ^

TypeError: Cannot read property 'empty_db' of undefined

which seems to be an issue with exporting datascript.core:

> let dsm = require('./datascript-mori.js');
undefined
> Object.keys(dsm.datascript)
[ 'db', 'impl', 'js' ]
>

Any ideas what I'm doing wrong?

Serialization to file

This issue might be off-topic, but I am developing a Node.js application. How can I easiest serialize/deserialize the database to/from a file? This is useful for saving the application state, so that I can restore it later.

Thank you for providing this library.

Javascript usage help request

Is there a way to query the db and get back mori values? Instead of javascript? Or should I just convert these values back somehow? Am I missing something? My goal would be to use the db as my state and immutable values even when it's not exactly the db I am working on, just results from it.

Warnings when building

Warning: implicit hook found: lein-git-deps.plugin/hooks 
Hooks are deprecated and will be removed in a future version.
Compiling ClojureScript...
Compiling ["release-js/datascript-mori.bare.js"] from ["src" ".lein-git-deps/mori/src"]...
WARNING: mori is a single segment namespace at line 1 /home/ashnur/repos/others/datascript-mori/.lein-git-deps/mori/src/mori.cljs
WARNING: var: datascript.js/schema->clj is not public at line 16 /home/ashnur/repos/others/datascript-mori/src/datascript_mori/core.cljs
WARNING: var: datascript.js/entity->clj is not public at line 17 /home/ashnur/repos/others/datascript-mori/src/datascript_mori/core.cljs
WARNING: var: datascript.js/entities->clj is not public at line 18 /home/ashnur/repos/others/datascript-mori/src/datascript_mori/core.cljs
WARNING: var: datascript.js/tempids->js is not public at line 19 /home/ashnur/repos/others/datascript-mori/src/datascript_mori/core.cljs
WARNING: var: datascript.js/tx-report->js is not public at line 20 /home/ashnur/repos/others/datascript-mori/src/datascript_mori/core.cljs
WARNING: var: datascript.js/pull-result->js is not public at line 22 /home/ashnur/repos/others/datascript-mori/src/datascript_mori/core.cljs
WARNING: var: datascript.js/keywordize is not public at line 23 /home/ashnur/repos/others/datascript-mori/src/datascript_mori/core.cljs
Packed release-js/datascript-mori.js
Successfully compiled ["release-js/datascript-mori.bare.js"] in 15.464 seconds.
  • implicit hook?
  • what is this about the 'not public', @bahulneel did I mess up something here?

Can't find db.fn/cas

How to do compare-and-swap? I can't find it anywhere. Tried multiple ways and gives back Unknown operation

Releasing 0.18.0

@ashnur How do we want to go about releasing 0.18.0 as I would like to start adopting it ASAP?

Maybe the thing to do is to release it on NPM scoped as @typeetfunc is responsible for the published module.

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.