| 1 |
|
%% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com> |
| 2 |
|
%% |
| 3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
|
%% you may not use this file except in compliance with the License. |
| 5 |
|
%% You may obtain a copy of the License at |
| 6 |
|
%% |
| 7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
%% |
| 9 |
|
%% Unless required by applicable law or agreed to in writing, software |
| 10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
|
%% See the License for the specific language governing permissions and |
| 13 |
|
%% limitations under the License. |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
-module(msmp_field). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-define(TIMEF_INT_OFS, 16#80_00_00). |
| 20 |
|
-export([is_character_type/1]). |
| 21 |
|
-export([is_numeric_type/1]). |
| 22 |
|
-export([lookup/1]). |
| 23 |
|
-export([types/0]). |
| 24 |
|
-export_type([type/0]). |
| 25 |
|
-include_lib("kernel/include/logger.hrl"). |
| 26 |
|
-on_load(on_load/0). |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
-type type() :: long |
| 30 |
|
| longlong |
| 31 |
|
| tiny |
| 32 |
|
| short |
| 33 |
|
| int24 |
| 34 |
|
| enum |
| 35 |
|
| string |
| 36 |
|
| varchar |
| 37 |
|
| date |
| 38 |
|
| time |
| 39 |
|
| time2 |
| 40 |
|
| timestamp2 |
| 41 |
|
| year |
| 42 |
|
| datetime |
| 43 |
|
| datetime2 |
| 44 |
|
| float |
| 45 |
|
| double |
| 46 |
|
| bit. |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
is_character_type(Type) -> |
| 50 |
:-( |
lists:member(Type, [string, var_string, varchar, blob]). |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
is_numeric_type(Type) -> |
| 54 |
29 |
lists:member( |
| 55 |
|
Type, |
| 56 |
|
[tiny, |
| 57 |
|
short, |
| 58 |
|
int24, |
| 59 |
|
long, |
| 60 |
|
longlong, |
| 61 |
|
year, |
| 62 |
|
float, |
| 63 |
|
double, |
| 64 |
|
decimal, |
| 65 |
|
newdecimal]). |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
on_load() -> |
| 69 |
1 |
persistent_term:put( |
| 70 |
|
?MODULE, |
| 71 |
|
msmp_enum:priv_consult("field-type.terms")). |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
types() -> |
| 75 |
28 |
persistent_term:get(?MODULE). |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
lookup(FieldType) -> |
| 79 |
28 |
maps:get(FieldType, types()). |