ExAirtable.Table behaviour (ExAirtable v0.2.5) View Source
The Table
behaviour allows you to define your own modules that use Airtables.
It is a thin wrapper around Service
, but often more convenient to use.
Examples
defmodule MyTable do
use ExAirtable.Table
def base, do: %ExAirtable.Config.Base{
id: "your base ID",
api_key: "your api key"
}
def name, do: "My Airtable Table Name"
end
iex> MyTable.list()
%ExAirtable.Airtable.List{}
iex> MyTable.retrieve("rec123")
%ExAirtable.Airtable.Record{}
Link to this section Summary
Link to this section Callbacks
Specs
base() :: ExAirtable.Config.Base.t()
A valid %ExAirtable.Config.Base{} config for your table.
Often this will end up being in the application configuration somewhere, for example:
# ... in your mix.config
config :my_app, Airtable.Base, %{
id: "base id",
api_key: "api key"
}
# ... in your table module
def base do
struct(ExAirtable.Config.Base, Application.get_env(:my_all, Airtable.Base))
end
Specs
name() :: String.t()
The name of your table within Airtable
Specs
schema() :: map()
(Optional) A map converting Airtable field names to local schema field names.
This is handy for situations (ecto schemas, for example) where you want different in-app field names than the fields you get from Airtable.
If you don't define this method, the default is to simply use Airtable field names as the schema.
Examples
# If you want atom field names for your schema map...
def schema do
%{
"Airtable Field Name" => :local_field_name,
"Other Airtable Field" => :other_local_field
}
end
iex> ExAirtable.Airtable.Record.to_schema(record, MyTable.schema)
%{local_field_name: "value", other_local_field: "other value"}
# If you want string field names for your schema map...
def schema do
%{
"Airtable Field Name" => "local_field_name",
"Other Airtable Field" => "other_local_field"
}
end
iex> ExAirtable.Airtable.Record.to_schema(record, MyTable.schema)
%{"local_field_name" => "value", "other_local_field" => "other value"}