tonsky/datascript

Cannot compare xxx to xxx

djyde opened this issue · 4 comments

djyde commented

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

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

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

djyde commented

It works. Thank you tonsky