View Source MishkaInstaller.Database.Helper (Mishka Installer v0.0.4)

This module provides some functions as utility tools to work with a database and other things.

Link to this section Summary

Functions

Helper function to keep PID alive for testing Genserver and database.

Converting string map to atom map.

If you need to convert database errors into a list, this function can be helpful. One of its uses can be correcting returned errors from the database into a list and converting it into JSON.

UUID validation.

UUID validation for ecto schema.

Link to this section Functions

Link to this function

allow_if_sandbox(parent_pid, orphan_msg \\ :stop)

View Source

Helper function to keep PID alive for testing Genserver and database.

reference

Reference

examples

Examples

MishkaInstaller.Database.Helper.allow_if_sandbox(pid)
Link to this function

convert_string_map_to_atom_map(map)

View Source
@spec convert_string_map_to_atom_map(map()) :: map()

Converting string map to atom map.

examples

Examples

MishkaInstaller.Database.Helper.convert_string_map_to_atom_map(%{"name" => "Mishka"})
Link to this function

translate_errors(changeset)

View Source
@spec translate_errors(Ecto.Changeset.t()) :: %{
  optional(atom()) => [binary() | map()]
}

If you need to convert database errors into a list, this function can be helpful. One of its uses can be correcting returned errors from the database into a list and converting it into JSON.

examples

Examples

MishkaInstaller.Database.Helper.translate_errors(changeset)
@spec uuid(any()) :: {:error, :uuid} | {:ok, :uuid, Ecto.UUID.t()}

UUID validation.

examples

Examples

MishkaInstaller.Database.Helper.uuid(12)
# OR
MishkaInstaller.Database.Helper.uuid("8c512ac2-e002-4589-a93f-b479e46c249d")
Link to this function

validate_binary_id(changeset, field, options \\ [])

View Source
@spec validate_binary_id(Ecto.Changeset.t(), atom(), any()) :: Ecto.Changeset.t()

UUID validation for ecto schema.

examples

Examples

MishkaInstaller.Database.Helper.validate_binary_id(12)
# OR
MishkaInstaller.Database.Helper.validate_binary_id("8c512ac2-e002-4589-a93f-b479e46c249d")