View Source Bonfire.Common.Needles.Tables (Bonfire v0.9.10-classic-beta.156)

Helpers for querying Needle types/tables

Summary

Functions

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.

Retrieves a single record by ID or filters.

Retrieves a single record by filters, raising an error if not found.

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

Lists IDs of all Pointable Tables.

Examples

iex> Bonfire.Common.Needles.Tables.list_ids()
["id1", "id2"]

Lists schemas of all Pointable Tables.

Examples

iex> Bonfire.Common.Needles.Tables.list_schemas()
[:schema1, :schema2]
Link to this function

list_tables(source \\ :code)

View Source

Lists all Pointable Tables.

Examples

iex> Bonfire.Common.Needles.Tables.list_tables()
[%Table{}]

iex> Bonfire.Common.Needles.Tables.list_tables(:db)
%{"table_name" => %Table{}}

Lists and debugs all Pointable Tables.

Examples

iex> 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

iex> Bonfire.Common.Needles.Tables.many(%{field: "value"})
{:ok, [%Table{}]}

Retrieves a single record by ID or filters.

Examples

iex> Bonfire.Common.Needles.Tables.one("valid_ulid")
{:ok, %Table{}}

iex> Bonfire.Common.Needles.Tables.one(%{field: "value"})
%Table{}

Retrieves a single record by filters, raising an error if not found.

Examples

iex> Bonfire.Common.Needles.Tables.one!(%{field: "value"})
%Table{}
Link to this function

schema_or_table!(schema_or_tablename_or_id)

View Source

Retrieves the schema or table name.

Examples

iex> Bonfire.Common.Needles.Tables.schema_or_table!("valid_id")
MySchema

iex> Bonfire.Common.Needles.Tables.schema_or_table!("table_name")
MySchema
Link to this function

table!(schema_or_tablename_or_id)

View Source
@spec table!(Needle.Pointer.t()) :: Needle.Table.t()

Retrieves the Table that a pointer points to.

Examples

iex> Bonfire.Common.Needles.Tables.table!(%Pointer{table_id: "valid_id"})
%Table{}

iex> Bonfire.Common.Needles.Tables.table!("valid_id")
%Table{}

iex> Bonfire.Common.Needles.Tables.table!("invalid_id")
# throws error

Retrieves fields of a table given a schema or table name.

Examples

iex> Bonfire.Common.Needles.Tables.table_fields(MySchema)
[:field1, :field2]

iex> Bonfire.Common.Needles.Tables.table_fields("table_name")
[:field1, :field2]
Link to this function

table_fields_meta(schema)

View Source

Retrieves metadata about fields of a table given a schema or table name.

Examples

iex> Bonfire.Common.Needles.Tables.table_fields_meta(MySchema)
[%{column_name: "field1", data_type: "type", column_default: nil, is_nullable: "NO"}]

iex> Bonfire.Common.Needles.Tables.table_fields_meta("table_name")
[%{column_name: "field1", data_type: "type", column_default: nil, is_nullable: "NO"}]