View Source Vtc.Ecto.Postgres.PgFramestamp (vtc v0.17.5)
Defines a composite type for storing rational values as a PgRational real-world playback seconds, PgFramerate pair.
These values are cast to Framestamp structs for use in application code.
The composite types is defined as follows:
CREATE TYPE framestamp AS (
__seconds_n bigint,
__seconds_d bigint,
__rate_n bigint,
__rate_d bigint,
__rate_tags framerate_tags[]
);
Field Access
framestamp's inner fields are considered semi-private to end-users. For working with the seconds / rate values, see create_func_seconds/0, create_func_rate/0, which create Postgres functions to act as getter functions for working with inner framestamp data.
SELECT (18018, 5, 24000, 1001, '{non_drop}')::framestamp
field-migrations
Field migrations
You can create framerate
fields during a migration like so:
alias Vtc.Framestamp
create table("events") do
add(:in, Framestamp.type())
add(:out, Framestamp.type())
end
Framestamp re-exports the Ecto.Type
implementation of this module,
and can be used any place this module would be used.
schema-fields
Schema fields
Then in your schema module:
defmodule MyApp.Event do
@moduledoc false
use Ecto.Schema
alias Vtc.Framestamp
@type t() :: %__MODULE__{
in: Framestamp.t(),
out: Framestamp.t()
}
schema "events" do
field(:in, Framestamp)
field(:out, Framestamp)
end
changesets
Changesets
With the above setup, changesets should just work:
def changeset(schema, attrs) do
schema
|> Changeset.cast(attrs, [:in, :out])
|> Changeset.validate_required([:in, :out])
end
Framerate values can be cast from the following values in changesets:
Framestamp structs.
Maps with the following format:
{ "smpte_timecode": "01:00:00:00", "rate": { "playback": [24000, 1001], "ntsc": "non_drop" } }
Where
smpte_timecode
is properly formatted SMPTE timecode string andplayback
is a map value supported by PgFramerate changeset casts.
fragments
Fragments
Framestamp values must be explicitly cast using type/2:
framestamp = Framestamp.with_frames!("01:00:00:00", Rates.f23_98())
query = Query.from(f in fragment("SELECT ? as r", type(^framestamp, Framestamp)), select: f.r)
Link to this section Summary
Types
Type of the raw composite value that will be sent to / received from the database.
Ecto Migrations
The database type for PgFramestamp.
Changeset Validations
Adds all constraints created by PgFramestamp.Migrations.create_constraints/3 to changeset.
Functions
The database type for PgFramerate.
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Link to this section Types
@type db_record() :: {non_neg_integer(), pos_integer(), non_neg_integer(), pos_integer(), [String.t()]}
Type of the raw composite value that will be sent to / received from the database.
Link to this section Ecto Migrations
@spec type() :: atom()
The database type for PgFramestamp.
Can be used in migrations as the fields type.
Link to this section Changeset Validations
@spec validate_constraints(Ecto.Changeset.t(data), atom(), [ Vtc.Ecto.Postgres.PgFramestamp.Migrations.constraint_opt() ]) :: Ecto.Changeset.t(data) when data: any()
Adds all constraints created by PgFramestamp.Migrations.create_constraints/3 to changeset.
arguments
Arguments
changeset
: The changeset being validated.field
: The field who's constraints are being checked.
options
Options
Pass the same options that were passed to PgFramestamp.Migrations.create_constraints/3
Link to this section Functions
@spec cast( Vtc.Framestamp.t() | %{required(String.t()) => any()} | %{required(atom()) => any()} ) :: {:ok, Vtc.Framerate.t()} | :error
The database type for PgFramerate.
Can be used in migrations as the fields type.
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.