fix model
This commit is contained in:
parent
c0254c5f93
commit
abb83c4f15
@ -85,7 +85,7 @@ handle_call(_Request, _From, State = #state{}) ->
|
|||||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
handle_cast({data, ServiceName, DeviceUUID, At, Tags, Fields}, State = #state{status = Status}) ->
|
handle_cast({data, ServiceName, DeviceUUID, At, Tags, Fields}, State = #state{status = Status}) ->
|
||||||
ok = data_model:insert(#micro_data{
|
ok = micro_data_model:insert(#micro_data{
|
||||||
device_uuid = DeviceUUID,
|
device_uuid = DeviceUUID,
|
||||||
service_name = ServiceName,
|
service_name = ServiceName,
|
||||||
at = At,
|
at = At,
|
||||||
@ -191,7 +191,7 @@ handle_info({server_push_message, PacketId, <<16:8, Directive>>}, State = #state
|
|||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
handle_info(fetch_next, State = #state{status = ?STATE_ACTIVATED, transport_pid = TransportPid}) ->
|
handle_info(fetch_next, State = #state{status = ?STATE_ACTIVATED, transport_pid = TransportPid}) ->
|
||||||
case data_model:fetch_next() of
|
case micro_data_model:fetch_next() of
|
||||||
error ->
|
error ->
|
||||||
ok;
|
ok;
|
||||||
{ok, #micro_data{device_uuid = DeviceUUID, service_name = ServiceName, at = At, tags = Tags, fields = Fields}} ->
|
{ok, #micro_data{device_uuid = DeviceUUID, service_name = ServiceName, at = At, tags = Tags, fields = Fields}} ->
|
||||||
|
|||||||
@ -33,5 +33,7 @@ start_mnesia() ->
|
|||||||
Tables = mnesia:system_info(tables),
|
Tables = mnesia:system_info(tables),
|
||||||
lager:debug("[efka_app] tables: ~p", [Tables]),
|
lager:debug("[efka_app] tables: ~p", [Tables]),
|
||||||
%% 创建数据库表
|
%% 创建数据库表
|
||||||
|
not lists:member(id_generator, Tables) andalso id_generator_model:create_table(),
|
||||||
not lists:member(micro_service, Tables) andalso micro_service_model:create_table(),
|
not lists:member(micro_service, Tables) andalso micro_service_model:create_table(),
|
||||||
|
not lists:member(micro_data, Tables) andalso micro_data_model:create_table(),
|
||||||
ok.
|
ok.
|
||||||
@ -6,7 +6,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%% Created : 06. 5月 2025 10:32
|
%%% Created : 06. 5月 2025 10:32
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(id_model).
|
-module(id_generator_model).
|
||||||
-author("anlicheng").
|
-author("anlicheng").
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
@ -6,7 +6,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%% Created : 04. 7月 2023 12:31
|
%%% Created : 04. 7月 2023 12:31
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(data_model).
|
-module(micro_data_model).
|
||||||
-author("aresei").
|
-author("aresei").
|
||||||
-include("efka_tables.hrl").
|
-include("efka_tables.hrl").
|
||||||
-include_lib("stdlib/include/qlc.hrl").
|
-include_lib("stdlib/include/qlc.hrl").
|
||||||
@ -28,7 +28,7 @@ create_table() ->
|
|||||||
|
|
||||||
-spec insert(MicroData0 :: #micro_data{}) -> ok | {error, Reason :: any()}.
|
-spec insert(MicroData0 :: #micro_data{}) -> ok | {error, Reason :: any()}.
|
||||||
insert(MicroData0 = #micro_data{}) ->
|
insert(MicroData0 = #micro_data{}) ->
|
||||||
MicroData = MicroData0#micro_data{id = id_model:next_id(?TAB)},
|
MicroData = MicroData0#micro_data{id = id_generator_model:next_id(?TAB)},
|
||||||
case mnesia:transaction(fun() -> mnesia:write(?TAB, MicroData, write) end) of
|
case mnesia:transaction(fun() -> mnesia:write(?TAB, MicroData, write) end) of
|
||||||
{'atomic', ok} ->
|
{'atomic', ok} ->
|
||||||
ok;
|
ok;
|
||||||
Loading…
x
Reference in New Issue
Block a user