Question on read operation (document type storage)
Closed this issue · 1 comments
Hi ,
I is it possible to have the following type of command in unqlite (similar to sqlite ) . If yes can anyone give an example , of how to do it?
SELECT
name,
milliseconds,
albumid
FROM
tracks
WHERE
albumid = 1;
name = ABC;
I tried the following
sprintf(script, "/* Create our filter callback*/"\
" $zCallback = function($rec){"\
" if( $rec.name == %s){"\
" return TRUE;"\
" }"\
" return FALSE;"\
" };"\
" $data = db_fetch_all('%s',$zCallback);"\
" print \"Fetched records\\n\";"\
" /*Iterate over the extracted elements*/"\
" foreach($data as $value){ /*JSON array holding the filtered records*/"\
" print $value..JX9_EOL;"\
" }", schema.name, col_name);
Yes. Your Jx9 code is correct. When running, it should output all the records stored in that collection and discard the items you want using your filter callback. A more elegant approach, is to use On Demand Object Allocation. That is, you create a new Jx9 variable on your C code using for example unqlite_vm_new_scalar() or unqlite_vm_new_array(), populate it with the value you want and you register it in your Jx9 VM using UNQLITE_VM_CONFIG_CREATE_VAR. Once done, this C variable shall become available to your running Jx9 script.