Selaa lähdekoodia

代码调整

erlArango_v1
SisMaker 5 vuotta sitten
vanhempi
commit
3ca84639c3
3 muutettua tiedostoa jossa 67 lisäystä ja 40 poistoa
  1. +33
    -23
      src/arangoApi/agDbMgr.erl
  2. +16
    -16
      src/httpCli/agHttpCli.erl
  3. +18
    -1
      src/httpCli/test.erl

+ 33
- 23
src/arangoApi/agDbMgr.erl Näytä tiedosto

@ -3,40 +3,50 @@
-compile([export_all, nowarn_export_all]).
%% _system访访
%% doc_address:https://www.arangodb.com/docs/stable/http/database-database-management.html
%%
%% /_api/database/properties
%% GET /_api/database/current
curDbInfo(PoolName) ->
agHttpCli:callAgency(PoolName, ?Get, <<"/_api/database/current">>, [], undefined).
curDbInfo(PoolNameOrSocket) ->
agHttpCli:callAgency(PoolNameOrSocket, ?Get, <<"/_api/database/current">>, [], undefined).
%% 访
%% GET /_api/database/user
userVisitDbs(PoolName) ->
agHttpCli:callAgency(PoolName, ?Get, <<"/_api/database/user">>, [], undefined, infinity, true).
curVisitDbs(PoolNameOrSocket) ->
agHttpCli:callAgency(PoolNameOrSocket, ?Get, <<"/_api/database/user">>, [], undefined).
%% _system数据库中创建新数据库
%%
%% GET /_api/database
curDbList(PoolNameOrSocket) ->
agHttpCli:callAgency(PoolNameOrSocket, ?Get, <<"/_api/database">>, [], undefined).
%%
%% POST /_api/database
% JSON对象是必需的
% name
% users使 root访
% username
% passwd
% activetruefalse
% extraJSON对象Extra中包含的数据 ArangoDB不会进一步解释
newDb(PoolName, Name) ->
NameStr = jiffy:encode(Name),
agHttpCli:callAgency(PoolName, ?Post, <<"/_api/database">>, [], [<<"{\"name\":">>, NameStr, <<"}">>], infinity, true).
newDb(PoolName, Name, Users) ->
BodyStr = jiffy:encode(#{<<"name">> => Name, <<"users">> => Users}),
agHttpCli:callAgency(PoolName, ?Post, <<"/_api/database">>, [], BodyStr, infinity, true).
% options
% sharding flexible single
% ReplicationFactor
% satellite satellite 1
% writeConcern
% DBServer上同步每个分片需要多少个副本
% writeConcern的值 ReplicationFactor
% users
% users或不包含任何用户使 root访
%
% username
% passwd
% activetruefalse
% extraJSON对象Extra中包含的数据 ArangoDB不会进一步解释
newDb(PoolNameOrSocket, Args) ->
BodyStr = jiffy:encode(Args),
agHttpCli:callAgency(PoolNameOrSocket, ?Post, <<"/_api/database">>, [], BodyStr, true).
%%
%% DELETE /_api/database/{database-name}
delDb(PoolName, Name) ->
delDb(PoolNameOrSocket, Name) ->
Path = <<"/_api/database/", Name/binary>>,
agHttpCli:callAgency(PoolName, ?Delete, Path, [], undefined, infinity, true).
agHttpCli:callAgency(PoolNameOrSocket, ?Delete, Path, [], undefined, true).

+ 16
- 16
src/httpCli/agHttpCli.erl Näytä tiedosto

@ -30,15 +30,15 @@
-spec callAgency(poolNameOrSocket(), method(), path(), headers(), body()) -> term() | {error, term()}.
callAgency(PoolNameOrSocket, Method, Path, Headers, Body) ->
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, ?DEFAULT_TIMEOUT, false).
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, false, ?DEFAULT_TIMEOUT).
-spec callAgency(poolNameOrSocket(), method(), path(), headers(), body(), timeout()) -> term() | {error, atom()}.
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, TimeOut) ->
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, TimeOut, false).
-spec callAgency(poolNameOrSocket(), method(), path(), headers(), body(), boolean()) -> term() | {error, atom()}.
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, IsSystem) ->
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, IsSystem, ?DEFAULT_TIMEOUT).
-spec callAgency(poolNameOrSocket(), method(), path(), headers(), body(), timeout(), boolean()) -> term() | {error, atom()}.
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, Timeout, IsSystem) ->
case castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), Timeout, IsSystem) of
-spec callAgency(poolNameOrSocket(), method(), path(), headers(), body(), boolean(), timeout()) -> term() | {error, atom()}.
callAgency(PoolNameOrSocket, Method, Path, Headers, Body, IsSystem, Timeout) ->
case castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), IsSystem, Timeout) of
{ok, RequestId} ->
receiveResponse(RequestId);
{error, _Reason} = Err ->
@ -49,18 +49,18 @@ callAgency(PoolNameOrSocket, Method, Path, Headers, Body, Timeout, IsSystem) ->
-spec castAgency(poolNameOrSocket(), method(), path(), headers(), body()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolNameOrSocket, Method, Path, Headers, Body) ->
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), ?DEFAULT_TIMEOUT, false).
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), false, ?DEFAULT_TIMEOUT).
-spec castAgency(poolNameOrSocket(), method(), path(), headers(), body(), timeout()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, Timeout) ->
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), Timeout, false).
-spec castAgency(poolNameOrSocket(), method(), path(), headers(), body(), boolean()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, IsSystem) ->
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), IsSystem, ?DEFAULT_TIMEOUT).
-spec castAgency(poolNameOrSocket(), method(), path(), headers(), body(), timeout(), boolean()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, Timeout, IsSystem) ->
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), Timeout, IsSystem).
-spec castAgency(poolNameOrSocket(), method(), path(), headers(), body(), boolean(), timeout()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, IsSystem, Timeout) ->
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), IsSystem, Timeout).
-spec castAgency(poolNameOrSocket(), method(), path(), headers(), body(), pid(), timeout(), boolean()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, Pid, Timeout, IsSystem) ->
-spec castAgency(poolNameOrSocket(), method(), path(), headers(), body(), pid(), boolean(), timeout()) -> {ok, requestId()} | {error, atom()}.
castAgency(PoolNameOrSocket, Method, Path, Headers, Body, Pid, IsSystem, Timeout) ->
OverTime =
case Timeout of
infinity -> infinity;

+ 18
- 1
src/httpCli/test.erl Näytä tiedosto

@ -44,4 +44,21 @@ test(N, Request) ->
%% test(N, Request) ->
%% erlang:put(cnt, N),
%% agHttpCli:callAgency(tt, Request, 5000),
%% test(N - 1, Request).
%% test(N - 1, Request).
tcjf(0, Args1) ->
Args = #{name => ffd, tet => "fdsff", <<"dfdf">> => 131245435346},
jiffy:encode(Args);
tcjf(N, Args1) ->
Args = #{name => ffd, tet => "fdsff", <<"dfdf">> => 131245435346},
jiffy:encode(Args),
tcjf(N - 1, Args1).
tcjx(0, Args1) ->
Args = {[{name, ffd}, {tet, "fdsff"}, {<<"dfdf">>, 131245435346}]},
jiffy:encode(Args);
tcjx(N, Args1) ->
Args = {[{name, ffd}, {tet, "fdsff"}, {<<"dfdf">>, 131245435346}]},
jiffy:encode(Args),
tcjx(N - 1, Args1).

Ladataan…
Peruuta
Tallenna