iot_cloud/apps/iot/src/database/endpoint_bo.erl
2025-08-12 16:58:41 +08:00

27 lines
927 B
Erlang

%%%-------------------------------------------------------------------
%%% @author aresei
%%% @copyright (C) 2023, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 16. 5月 2023 12:48
%%%-------------------------------------------------------------------
-module(endpoint_bo).
-author("aresei").
-include("iot.hrl").
%% API
-export([get_all_endpoints/0, get_endpoint_by_id/1]).
-spec get_all_endpoints() -> EndpointIds :: [integer()].
get_all_endpoints() ->
case mysql_pool:get_all(mysql_iot, <<"SELECT id FROM endpoint where status = 1">>) of
{ok, Endpoints} ->
lists:map(fun(#{<<"id">> := Id}) -> Id end, Endpoints);
{error, _} ->
[]
end.
-spec get_endpoint_by_id(Id :: integer()) -> undefined | {ok, EndpointInfo :: map()}.
get_endpoint_by_id(Id) when is_integer(Id) ->
mysql_pool:get_row(mysql_iot, <<"SELECT * FROM endpoint WHERE id = ? and status = 1 LIMIT 1">>, [Id]).