View Source Vtc.Ecto.Postgres.PgFramestamp (vtc v0.13.9)

Defines a composite type for storing rational values as a PgRational real-world playbck 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 rational,
  rate framerate
)
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 and playback 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.

Functions

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

The database type for PgFramerate.

Link to this section Types

Type of the raw composite value that will be sent to / received from the database.

Link to this section Functions

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

@spec type() :: atom()

The database type for PgFramerate.

Can be used in migrations as the fields type.