tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.49k stars 309 forks source link

Cannot compare xxx to xxx #429

Closed djyde closed 2 years ago

djyde commented 2 years ago

I tried to use the output of serializable to generate a db use from_serialize. But I got the Cannot compare xxx to xxx error.

import d from 'datascript';

const data = {
  count: 6,
  tx0: 536870912,
  'max-eid': 3,
  'max-tx': 536870915,
  schema:
    '{":card/uid" {:db/unique :db.unique/identity}, ":card/content" {:db/cardinality :db.cardinality/one}, ":card/child" {:db/cardinality :db.cardinality/many, :db/valueType :db.type/ref}, ":card/parent" {:db/cardinality :db.cardinality/one, :db/valueType :db.type/ref}}',
  attrs: [':card/content', ':card/uid'],
  keywords: [],
  eavt: [
    [1, 0, 'card 1', 1],
    [1, 1, 'HS04k6W1', 1],
    [2, 0, 'card 2', 2],
    [2, 1, 'D6VstsyL', 2],
    [3, 0, 'card 3', 3],
    [3, 1, 'mmP5USvN', 3],
  ],
  aevt: [0, 2, 4, 1, 3, 5],
  avet: [3, 1, 5],
};

const conn = d.conn_from_db(d.from_serializable(data));

d.q(
  `
[:find ?uid ?content
  :where
  [?eid ":card/content" ?content]
  [?eid ":card/uid" ?uid]
]
    `,
  d.db(conn)
);

If i remove the "" from the query, then it works:

d.q(
  `
[:find ?uid ?content
  :where
  [?eid :card/content ?content]
  [?eid :card/uid ?uid]
]
    `,
  d.db(conn)
);

You could try this demo online: https://stackblitz.com/edit/typescript-t8txhv?devtoolsheight=33&file=index.ts

djyde commented 2 years ago

The werid thing is, if I query in a db that created by create_conn(schema), when I query without a "", it happend again:

https://stackblitz.com/edit/js-5ngryk?devtoolsheight=33&file=index.js

tonsky commented 2 years ago

Should be fixed in 1.3.11, please let me know if it works. As a general rule, quotes are required around attributes when using JS API

tonsky commented 2 years ago

642275d9f449230c08c425a65398fb6c02cbf070

djyde commented 2 years ago

It works. Thank you tonsky