View Source Bonfire.Common.Needles.Tables (Bonfire v0.9.11-social-beta.6)
Helpers for querying Needle
types/tables
Summary
Functions
Checks if a schema represents a mixin by checking if it's listed in the parent schema's mixin associations.
Lists IDs of all Pointable Tables.
Lists schemas of all Pointable Tables.
Lists all Pointable Tables.
Lists and debugs all Pointable Tables.
Retrieves details of multiple tables based on filters.
Returns the module name of an association if it represents a mixin by checking if it's listed in the parent schema's mixin associations.
Returns the module name of an association
Checks if a schema represents a mixin by checking if it's listed in the parent schema's mixin associations.
Retrieves a single record by ID or filters.
Retrieves a single record by filters, raising an error if not found.
Retrieves schema mixins for a given Ecto struct.
Retrieves schema mixins for a given Ecto struct.
Retrieves a list of schema mixins that aren't loaded in the given Ecto struct.
Retrieves the schema or table name.
Retrieves the Table that a pointer points to.
Retrieves fields of a table given a schema or table name.
Retrieves metadata about fields of a table given a schema or table name.
Functions
Checks if a schema represents a mixin by checking if it's listed in the parent schema's mixin associations.
Examples
iex> assoc_mixin_of?(:character, Bonfire.Data.Identity.User)
true
iex> assoc_mixin_of?(:non_existing_assoc_name, Bonfire.Data.Identity.User)
false
Lists IDs of all Pointable Tables.
Examples
> Bonfire.Common.Needles.Tables.list_ids()
["id1", "id2"]
Lists schemas of all Pointable Tables.
Examples
iex> schemas = Bonfire.Common.Needles.Tables.list_schemas()
iex> true = Enum.member?(schemas, Needle.Table)
Lists all Pointable Tables.
Examples
iex> tables = Bonfire.Common.Needles.Tables.list_tables()
iex> tables = Bonfire.Common.Needles.Tables.list_tables(:db)
Lists and debugs all Pointable Tables.
Examples
> Bonfire.Common.Needles.Tables.list_tables_debug()
[{:ok, "table1"}, {:error, "Code and DB have differing IDs for the same table", "table2", "id2a", "id2b"}, {:error, "Table present in DB but not in code", "table3"}]
Retrieves details of multiple tables based on filters.
Examples
> Bonfire.Common.Needles.Tables.many(%{field: "value"})
{:ok, [%Table{}]}
Returns the module name of an association if it represents a mixin by checking if it's listed in the parent schema's mixin associations.
Examples
iex> maybe_assoc_mixin_module(:character, Bonfire.Data.Identity.User)
Bonfire.Data.Identity.Character
iex> maybe_assoc_mixin_module(:non_existing_assoc_name, Bonfire.Data.Identity.User)
nil
Returns the module name of an association
Examples
iex> maybe_assoc_module(:character, Bonfire.Data.Identity.User)
Bonfire.Data.Identity.Character
iex> maybe_assoc_module(:non_existing_assoc_name, Bonfire.Data.Identity.User)
nil
Checks if a schema represents a mixin by checking if it's listed in the parent schema's mixin associations.
Examples
iex> module_mixin_of?(Bonfire.Data.Identity.Character, Bonfire.Data.Identity.User)
true
iex> module_mixin_of?(Needle.Table, Bonfire.Data.Identity.User)
false
Retrieves a single record by ID or filters.
Examples
> Bonfire.Common.Needles.Tables.one("valid_ulid")
{:ok, %Table{}}
> Bonfire.Common.Needles.Tables.one(%{field: "value"})
%Table{}
Retrieves a single record by filters, raising an error if not found.
Examples
> Bonfire.Common.Needles.Tables.one!(%{field: "value"})
%Table{}
Retrieves schema mixins for a given Ecto struct.
Examples
iex> schemas = schema_mixin_assocs(Bonfire.Data.Identity.User)
iex> true = Enum.member?(schemas, :character)
Retrieves schema mixins for a given Ecto struct.
Examples
iex> schemas = schema_mixin_modules(Bonfire.Data.Identity.User)
iex> true = Enum.member?(schemas, Bonfire.Data.Identity.Character)
Retrieves a list of schema mixins that aren't loaded in the given Ecto struct.
Examples
> schema_mixins(%Bonfire.Data.Identity.User{})
[:account]
Retrieves the schema or table name.
Examples
iex> Bonfire.Common.Needles.Tables.schema_or_table!("5EVSER1S0STENS1B1YHVMAN01D")
Bonfire.Data.Identity.User
iex> Bonfire.Common.Needles.Tables.schema_or_table!("bonfire_data_identity_user")
Bonfire.Data.Identity.User
@spec table!(Needle.Pointer.t()) :: Needle.Table.t()
Retrieves the Table that a pointer points to.
Examples
> Bonfire.Common.Needles.Tables.table!(%Pointer{table_id: "valid_id"})
%Table{}
> Bonfire.Common.Needles.Tables.table!("valid_id")
%Table{}
> Bonfire.Common.Needles.Tables.table!("invalid_id")
# throws error
Retrieves fields of a table given a schema or table name.
Examples
> Bonfire.Common.Needles.Tables.table_fields(MySchema)
[:field1, :field2]
> Bonfire.Common.Needles.Tables.table_fields("table_name")
[:field1, :field2]
Retrieves metadata about fields of a table given a schema or table name.
Examples
> Bonfire.Common.Needles.Tables.table_fields_meta(MySchema)
[%{column_name: "field1", data_type: "type", column_default: nil, is_nullable: "NO"}]
> Bonfire.Common.Needles.Tables.table_fields_meta("table_name")
[%{column_name: "field1", data_type: "type", column_default: nil, is_nullable: "NO"}]