anchor.diff:              Priv
       end;
   
  +% generate sql from table data
  +process_cmd({[<<"get_sql">>], ReqBody}, _Sess, _UserId, From, Priv) ->
  +    [{<<"get_sql">>, BodyJson}] = ReqBody,
  +    Statement = binary_to_term(base64:decode(proplists:get_value(<<"statement">>, BodyJson, <<>>))),
  +    ColumnIds = proplists:get_value(<<"columnIds">>, BodyJson, []),
  +    RowIds = proplists:get_value(<<"rowIds">>, BodyJson, []),
  +    Operation = proplists:get_value(<<"op">>, BodyJson, <<>>),
  +    Columns = Statement:get_columns(),
  +    TableName = Statement:get_table_name(),
  +    Rows = [Statement:row_with_key(Id) || Id <- RowIds],
  +    Sql = generate_sql(TableName, Operation, Rows, Columns, ColumnIds),
  +    Response = jsx:encode([{<<"get_sql">>, [{<<"sql">>, Sql}, {<<"title">>, <<"Generated Sql">>}]}]),
  +    From ! {reply, Response},
  +    Priv;
  +
   % events
   process_cmd({[<<"sort">>], ReqBody}, _Sess, _UserId, From, Priv) ->
       [{<<"sort">>,BodyJson}] = ReqBody,
  
positive.code:     end;
  check_funs(Error) ->
      Error.
  
negative.code:                                        , sortFun                    = SortFun
                                         , sortSpec                   = SortSpec
                                         , orig_qry                   = Query
                                         , table_name                 = TableName
                                         , block_length               = ?DEFAULT_ROW_SIZE
                                         , fetch_recs_async_fun       = fun(Opts) -> Connection:run_cmd(fetch_recs_async, [Opts, StmtRef]) end
                                         , fetch_close_fun            = fun() -> Connection:run_cmd(fetch_close, [StmtRef]) end
  