Skip to main content

src/gdo@value.erl

-module(gdo@value).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gdo/value.gleam").
-export([type_name/1, is_null/1, param_value/1]).
-export_type([db_value/0, param/0]).

-type db_value() :: null |
    {int, integer()} |
    {float, float()} |
    {bool, boolean()} |
    {string, binary()} |
    {bytes, bitstring()}.

-type param() :: {positional, db_value()} | {named, binary(), db_value()}.

-file("src/gdo/value.gleam", 15).
-spec type_name(db_value()) -> binary().
type_name(Value) ->
    case Value of
        null ->
            <<"null"/utf8>>;

        {int, _} ->
            <<"int"/utf8>>;

        {float, _} ->
            <<"float"/utf8>>;

        {bool, _} ->
            <<"bool"/utf8>>;

        {string, _} ->
            <<"string"/utf8>>;

        {bytes, _} ->
            <<"bytes"/utf8>>
    end.

-file("src/gdo/value.gleam", 26).
-spec is_null(db_value()) -> boolean().
is_null(Value) ->
    case Value of
        null ->
            true;

        _ ->
            false
    end.

-file("src/gdo/value.gleam", 33).
-spec param_value(param()) -> db_value().
param_value(Param) ->
    case Param of
        {positional, Value} ->
            Value;

        {named, _, Value@1} ->
            Value@1
    end.