typedb / typedb-driver

TypeDB Drivers for Rust, Python, Java, Node.js, C, C++, and C#.
https://typedb.com
Apache License 2.0
34 stars 32 forks source link

Send multiple queries in a single method call (detection of query start and end) #475

Open xDaya opened 1 year ago

xDaya commented 1 year ago

Problem to Solve

Currently, it is not possible to send multiple queries to TypeDB at once. When passing to tx.query(), each query needs to be passed separately. Example: It is not possible to do: tx.query("insert $condition isa condition, has condition_type 'startcondition'; insert $context isa context, has context_id 'context_1663593133.555721'; match $object isa resource, has obj_type 'rock', has size 'large', has color 'grey';") Instead, it only works like this: tx.query("insert $condition isa condition, has condition_type 'startcondition';") tx.query("insert $context isa context, has context_id 'context_1663593133.555721';") tx.query("match $object isa resource, has obj_type 'rock', has size 'large', has color 'grey';")

Proposed Solution

It would be great if multiple queries could be passed at once, and the start and end of a query would be detected automatically. This is similar to what happens in TypeDB Studio, when creating a .tql file that contains multiple queries.

alexjpwalker commented 1 year ago

This would most likely be achieved by providing a generic tx.query().generic() or tx.query().script() method that takes in any TypeQL script and sends it to the server, returning either "success" or "error".

Another possible approach to this problem in the future will come when https://github.com/typedb-osi/typeql-lang-python is completed, as it will provide the ability to parse a string containing multiple queries - something like typeql.parse_queries(raw_string). Each query will be of a specific query class, which will then be providable to the relevant method in typedb_client. TypeDB Studio uses this approach. Its advantage is that the answers of any Match queries will be returned to the client application.