%%%------------------------------------------------------------------- %%% @author aresei %%% @copyright (C) 2023, %%% @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]).