#
View Source Vtc.Ecto.Postgres.PgFramestamp (vtc v0.13.15)

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

db_record()

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

## Changeset Validations

validate_constraints(changeset, field, opts \\ [])

Adds all constraints created by PgFramestamp.Migrations.create_constraints/3 to changeset.

## Functions

embed_as(_)

Callback implementation for `Ecto.Type.embed_as/1`.

equal?(term1, term2)

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

type()

The database type for PgFramerate.

# Link to this section Types

Link to this type

# db_record()

View Source

    @type db_record() ::
      {Vtc.Ecto.Postgres.PgRational.db_record(),
       Vtc.Ecto.Postgres.PgFramerate.db_record()}

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

# Link to this section Changeset Validations

Link to this function

# validate_constraints(changeset, field, opts \\ [])

View Source

    @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.

##

options

Options

Pass the same options that were passed to PgFramestamp.Migrations.create_constraints/3

# Link to this section Functions

Link to this function

# embed_as(_)

View Source

Callback implementation for `Ecto.Type.embed_as/1`.

Link to this function

# equal?(term1, term2)

View Source

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

Link to this function

# type()

View Source

    @spec type() :: atom()

The database type for PgFramerate.

Can be used in migrations as the fields type.