Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chitika/cberl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: muut/cberl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 8 commits
  • 7 files changed
  • 2 contributors

Commits on Apr 18, 2016

  1. Copy the full SHA
    089e0ca View commit details
  2. Copy the full SHA
    abfa4a6 View commit details

Commits on Apr 19, 2016

  1. allowing use of CAS property in set

    For situations where you don't want to replace a value if the record has been modified since the last read a CAS value is passed from the last read.
    courtneycouch committed Apr 19, 2016
    Copy the full SHA
    5815b58 View commit details
  2. version bump

    courtneycouch committed Apr 19, 2016
    Copy the full SHA
    ffdef12 View commit details
  3. Copy the full SHA
    491feca View commit details
  4. updated changelog

    courtneycouch committed Apr 19, 2016
    Copy the full SHA
    deac9d4 View commit details

Commits on May 1, 2016

  1. using flags compatible with other client sdks

    transcoder is still backwards compatible in that it can decode data written by older versions of this library *but* older versions of this library will not be able to decode data written by this version.
    
    This change makes cberl compatible with other languages client libraries.
    
    More info here: http://developer.couchbase.com/documentation/server/current/developer-guide/transcoders.html#story-h2-5
    courtneycouch committed May 1, 2016
    Copy the full SHA
    a00caf0 View commit details
  2. version bump to 1.1.0

    for flag changes (potentially breaking change)
    courtneycouch committed May 1, 2016
    Copy the full SHA
    9154332 View commit details
Showing with 75 additions and 10 deletions.
  1. +13 −0 CHANGELOG
  2. +4 −2 c_src/cb.c
  3. +1 −1 rebar.config
  4. +1 −1 src/cberl.app.src
  5. +11 −3 src/cberl.erl
  6. +16 −3 src/cberl_transcoder.erl
  7. +29 −0 test/cberl_tests.erl
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
-- 1.1.0 (2016-5-1)
Updated to use modern encoding flags.

Old versions of this library will not be able to read data inserted by this version, but this version will be able to read and decode older data.

See: http://developer.couchbase.com/documentation/server/current/developer-guide/transcoders.html#story-h2-5

-- 1.0.7 (2016-4-18)
Added support for N1QL HTTP request types

-- 1.0.6 (2016-4-18)
Added CAS option support for cberl:set

-- 1.0.5 (2014-12-17)
Fix append function with newer versions of libcouchbase.

6 changes: 4 additions & 2 deletions c_src/cb.c
Original file line number Diff line number Diff line change
@@ -629,8 +629,10 @@ ERL_NIF_TERM cb_http(ErlNifEnv* env, handle_t* handle, void* obj)

lcb_http_cmd_t cmd;
cmd.version = 0;
cmd.v.v0.path = args->path;
cmd.v.v0.npath = strlen(args->path);
if (args->type != 3) {
cmd.v.v0.path = args->path;
cmd.v.v0.npath = strlen(args->path);
}
cmd.v.v0.body = args->body;
cmd.v.v0.nbody = strlen(args->body);
cmd.v.v0.method = args->method;
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

{deps, [
{'jiffy', "", {git, "git://github.com/davisp/jiffy.git", {branch, master}}},
{'poolboy', "", {git, "git://github.com/devinus/poolboy.git", {branch, master}}}
{poolboy, "1.5.1"}
]}.

{erl_opts, [debug_info, warnings_as_errors]}.
2 changes: 1 addition & 1 deletion src/cberl.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, cberl,
[
{description, ""},
{vsn, "1.0.6"},
{vsn, "1.1.0"},
{registered, []},
{applications, [
kernel,
14 changes: 11 additions & 3 deletions src/cberl.erl
Original file line number Diff line number Diff line change
@@ -3,13 +3,13 @@
%%% @version 1.0.5

-module(cberl).
-vsn("1.0.5").
-vsn("1.1.0").
-include("cberl.hrl").

-export([start_link/2, start_link/3, start_link/5, start_link/6, start_link/7]).
-export([stop/1]).
%% store operations
-export([add/4, add/5, replace/4, replace/5, set/4, set/5, store/7]).
-export([add/4, add/5, replace/4, replace/5, set/4, set/5, set/6, store/7]).
%% update operations
-export([append/3, prepend/3, touch/3, mtouch/3]).
-export([incr/3, incr/4, incr/5, decr/3, decr/4, decr/5]).
@@ -101,6 +101,13 @@ set(PoolPid, Key, Exp, Value) ->
set(PoolPid, Key, Exp, Value, TranscoderOpts) ->
store(PoolPid, set, Key, Value, TranscoderOpts, Exp, 0).


%% @equiv store(PoolPid, set, "", Key, Value, Exp)
-spec set(pid(), key(), integer(), value(), atom(), integer()) -> ok | {error, _}.
set(PoolPid, Key, Exp, Value, TranscoderOpts, Cas) ->
store(PoolPid, set, Key, Value, TranscoderOpts, Exp, Cas).


%%%%%%%%%%%%%%%%%%%%%%%%%
%%% UPDATE OPERATIONS %%%
%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -361,7 +368,8 @@ execute(PoolPid, Cmd) ->

http_type(view) -> 0;
http_type(management) -> 1;
http_type(raw) -> 2.
http_type(raw) -> 2;
http_type(n1ql) -> 3.

http_method(get) -> 0;
http_method(post) -> 1;
19 changes: 16 additions & 3 deletions src/cberl_transcoder.erl
Original file line number Diff line number Diff line change
@@ -3,9 +3,16 @@
-include("cberl.hrl").

-define('CBE_NONE', 0).
-define('CBE_JSON', 16#0002).
-define('CBE_RAW', 16#0004).
-define('CBE_STR', 16#0008).

%%couchbase standardized flags
-define('CBE_JSON', 16#02 bsl 24).
-define('CBE_RAW', 16#03 bsl 24).
-define('CBE_STR', 16#04 bsl 24).

%%old cberl specific flags (necessary to decode data inserted by older cberl versions)
-define('CBE_JSON_LEGACY', 16#0002).
-define('CBE_RAW_LEGACY', 16#0004).
-define('CBE_STR_LEGACY', 16#0008).

-define(STANDARD_FLAG, json).

@@ -29,10 +36,16 @@ encode_value1(_, Value) ->
-spec decode_value(integer(), value()) -> value().
decode_value(Flag, Value) when ?'CBE_RAW' band Flag == ?'CBE_RAW' ->
decode_value(Flag bxor ?'CBE_RAW', binary_to_term(Value));
decode_value(Flag, Value) when ?'CBE_RAW_LEGACY' band Flag == ?'CBE_RAW_LEGACY' ->
decode_value(Flag bxor ?'CBE_RAW_LEGACY', binary_to_term(Value));
decode_value(Flag, Value) when ?'CBE_JSON' band Flag == ?'CBE_JSON' ->
decode_value(Flag bxor ?'CBE_JSON', jiffy:decode(Value));
decode_value(Flag, Value) when ?'CBE_JSON_LEGACY' band Flag == ?'CBE_JSON_LEGACY' ->
decode_value(Flag bxor ?'CBE_JSON_LEGACY', jiffy:decode(Value));
decode_value(Flag, Value) when ?'CBE_STR' band Flag == ?'CBE_STR' ->
decode_value(Flag bxor ?'CBE_STR', binary_to_list(Value));
decode_value(Flag, Value) when ?'CBE_STR_LEGACY' band Flag == ?'CBE_STR_LEGACY' ->
decode_value(Flag bxor ?'CBE_STR_LEGACY', binary_to_list(Value));
decode_value(_, Value) ->
Value.

29 changes: 29 additions & 0 deletions test/cberl_tests.erl
Original file line number Diff line number Diff line change
@@ -5,12 +5,14 @@
cberl_test_() ->
[{foreach, fun setup/0, fun clean_up/1,
[fun test_set_and_get/1,
fun test_set_cas/1,
fun test_replace_add/1,
fun test_multi_get/1,
fun test_get_and_touch/1,
fun test_append_prepend/1,
fun test_remove/1,
fun test_touch/1,
fun test_query/1,
fun test_lock/1,
fun test_flush/1,
fun test_flush_1/1]}].
@@ -51,6 +53,26 @@ test_set_and_get(_) ->
?_assertMatch({Key, _, Value}, Get3)
].

test_set_cas(_) ->
Key = <<"testkey">>,
Value = "testval",
Value2 = "testval2",
Value3 = "testval3",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{_, Cas1, _} = cberl:get(?POOLNAME, Key),
ok = cberl:set(?POOLNAME, Key, 0, Value2, standard, Cas1),
{_, Cas2, Value2} = cberl:get(?POOLNAME, Key),
SetFail = cberl:set(?POOLNAME, Key, 0, Value3, standard, Cas1),
{_, Cas2, Value3failed} = cberl:get(?POOLNAME, Key),
ok = cberl:set(?POOLNAME, Key, 0, Value3, standard, Cas2),
{_, _, Value3Success} = cberl:get(?POOLNAME, Key),
[?_assertEqual({error, key_eexists}, SetFail),
?_assertEqual(Value3failed, Value2),
?_assertEqual(Value3Success, Value3)
].



test_multi_get(_) ->
Value = "testval",
Keys = lists:map(fun(N) -> list_to_binary(integer_to_list(N)) end, lists:seq(1, 1000)),
@@ -106,6 +128,13 @@ test_remove(_) ->
ok = cberl:remove(?POOLNAME, Key),
[?_assertEqual({Key, {error,key_enoent}}, cberl:get(?POOLNAME, Key))].

test_query(_) ->
Query = "statement=SELECT * FROM default LIMIT 1",
ContentType = "application/x-www-form-urlencoded",
Result = cberl:http(?POOLNAME, "", Query, ContentType, post, n1ql),
[?_assertMatch({ok, 200, _}, Result)
].

test_lock(_) ->
Key = <<"testkey">>,
Value = "testval",