cozodb / cozo

A transactional, relational-graph-vector database that uses Datalog for query. The hippocampus for AI!
https://cozodb.org
Mozilla Public License 2.0
3.44k stars 108 forks source link

`export_relations` call signature for web wasm runtime #200

Open chuanqisun opened 1 year ago

chuanqisun commented 1 year ago

After reading the docs on export_relations, I was under the impression that the following would work in the web wasm runtime:

db.export_relations(`["my_relation_1", "my_relation_2"]`)

But it throws an error invalid type: string \"my_relation_1\", expected a sequence at line 1 column 17

After trial and error, I found the correct call signature to be either

db.export_relations(`{"relations": ["my_relation_1", "my_relation_2"]}`)

or, more surprisingly,

db.export_relations(`[["my_relation_1", "my_relation_2"]]`)

Assuming my initial impression was the intended design, I wonder if there would be similar issues with Java, Swift, and C runtimes that all share the underlying the export _relations_str call. Python and Node.js runtime are good because they are responsible for creating the Iterator before passing into the core.

Related source here: https://github.com/cozodb/cozo/blob/f79c9b1c150ebb24d3e106be8f077c47f9a89b37/cozo-core/src/lib.rs#L283-L294

Related doc here: https://github.com/cozodb/cozo-docs/blob/6cf59929c4b13c8e647cb38297f32d9a9f4fccdc/source/nonscript.rst?plain=1#L16-L22