niamtokik / cozo

An interface to cozodb
https://github.com/niamtokik/cozo
BSD 2-Clause "Simplified" License
7 stars 1 forks source link

Rethink interfaces and how to deal with queries/responses #16

Open niamtokik opened 1 year ago

niamtokik commented 1 year ago

The current structure is simple, we generate a query from a string and receive the result as json. A more Erlangish way should be used.

niamtokik commented 1 year ago

Some draft...

?[f1, f2, f3] <- [
  [1,2,3]
  [2, 3, 4]
]
:put test{f1, f2, f3}
-record(test, { f1 :: integer(), f2 :: integer(), f3 :: integer() }).

% create a new table using test record
cozo:create_table(Db, #test{}).

% create a list of data to insert
Data = [
  #test{ f1 = 1, f2 = 2, f3 = 3 },
  #test{ f1 = 2, f2 = 3, f3 = 4 }
].

% insert all data
cozo:put(Db, Data).

Types conversion from Erlang to Cozoscript (first)

Numbers

cozo_parse:from_erlang({ integer, 123 }).
%

cozo_parse:from_erlang({ float, 123.123 }).
%

cozo_parse:from_erlang({ number, 123 }).
% 
{integer, 123}
{float, 123.123}
{number, 123}
{list, [{integer, 123}]}
{string, <<"test">>}