How to use datascript - 9 common examples

To help you get started, we’ve selected a few datascript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gurdasnijor / react-datascript / src / withDatascriptQuery.js View on Github external
if (query) {
          const qArgs = [query, datascript.db(this.conn)];
          if (params) {
            qArgs.push(params);
          }
          if (rules) {
            qArgs.push(rules);
          }
          let queryResult = datascript.q(...qArgs);
          this.setState({ result: queryResult || this.state.result });
          return;
        }

        if (pull) {
          const { entityIds } = this.props;
          let queryResult = datascript.pull_many(datascript.db(this.conn), pull, entityIds);
          this.setState({ result: queryResult || this.state.result });
          return;
        }

        if (dbConn) {
          let queryResult = dbConn(this.conn);
          this.setState({ result: queryResult || this.state.result });
        }
      }
github gurdasnijor / react-datascript / src / withDatascriptQuery.js View on Github external
const { result, params, parsedQueryAttrs } = this.state;

        if (report) {
          const someQueryAttrChanged = report.tx_data
            .map(({a}) => a)
            .some(a => parsedQueryAttrs[a]);

          //Did this last transaction not contain changes to any fields referenced
          //by this query?  Skip the re-query (and corresponding component update)
          if (query && !someQueryAttrChanged) {
            return;
          }
        }

        if (query) {
          const qArgs = [query, datascript.db(this.conn)];
          if (params) {
            qArgs.push(params);
          }
          if (rules) {
            qArgs.push(rules);
          }
          let queryResult = datascript.q(...qArgs);
          this.setState({ result: queryResult || this.state.result });
          return;
        }

        if (pull) {
          const { entityIds } = this.props;
          let queryResult = datascript.pull_many(datascript.db(this.conn), pull, entityIds);
          this.setState({ result: queryResult || this.state.result });
          return;
github gurdasnijor / react-datascript / examples / follower-graph / components.js View on Github external
dbConn: (conn) => (
    datascript.datoms(datascript.db(conn), ':aevt', 'name')
  )
});
github gurdasnijor / react-datascript / src / withDatascriptQuery.js View on Github external
transactData = (data, txMsg) => {
        datascript.transact(this.conn, data, txMsg);
      }
github gurdasnijor / react-datascript / examples / follower-graph / createDBConn.js View on Github external
{
      ':db/id': -2,
      name: 'David',
      follows: [-3, -1]
    },
    {
      ':db/id': -3,
      name: 'Jane'
    }
  ];

  /**
   * Transact in the data, to be stored and indexed by datascript for performant
   * querying.
   */
  datascript.transact(conn, datoms);
  return conn;
};
github gurdasnijor / react-datascript / examples / follower-graph / createDBConn.js View on Github external
*/
  const twitterUserSchema = {
    name: {
      ':db/cardinality': ':db.cardinality/one',
      ':db/unique': ':db.unique/identity'
    },
    follows: {
      ':db/cardinality': ':db.cardinality/many',
      ':db/valueType': ':db.type/ref'
    }
  };

  /**
   * Create connection to db (that's been instantiated with the schema above.)
   */
  const conn = datascript.create_conn(twitterUserSchema);

  /**
   * Define some seed data; including some `follower` references (that make
   * use of a temporary id to point to other entities within the array.)
   */
  const datoms = [
    {
      ':db/id': -1,
      name: 'John',
      follows: -3
    },
    {
      ':db/id': -2,
      name: 'David',
      follows: [-3, -1]
    },
github gurdasnijor / react-datascript / src / withDatascriptQuery.js View on Github external
componentWillMount() {
        this.execQuery();
        datascript.listen(this.conn, this.execQuery);
      }
github gurdasnijor / react-datascript / src / withDatascriptQuery.js View on Github external
//Did this last transaction not contain changes to any fields referenced
          //by this query?  Skip the re-query (and corresponding component update)
          if (query && !someQueryAttrChanged) {
            return;
          }
        }

        if (query) {
          const qArgs = [query, datascript.db(this.conn)];
          if (params) {
            qArgs.push(params);
          }
          if (rules) {
            qArgs.push(rules);
          }
          let queryResult = datascript.q(...qArgs);
          this.setState({ result: queryResult || this.state.result });
          return;
        }

        if (pull) {
          const { entityIds } = this.props;
          let queryResult = datascript.pull_many(datascript.db(this.conn), pull, entityIds);
          this.setState({ result: queryResult || this.state.result });
          return;
        }

        if (dbConn) {
          let queryResult = dbConn(this.conn);
          this.setState({ result: queryResult || this.state.result });
        }
      }
github gurdasnijor / react-datascript / src / withDatascriptQuery.js View on Github external
componentWillUnmount() {
        datascript.unlisten(this.conn);
      }

datascript

Immutable in-memory triplestore with Datalog queries

EPL-1.0
Latest version published 4 months ago

Package Health Score

72 / 100
Full package analysis