Sow.Sync (Sow v0.1.4)

Copy Markdown View Source

Handles synchronization of fixture records to the database.

The sync process:

  1. Resolves all relations (syncs dependencies first, collects their IDs)
  2. Prepares the record with resolved foreign keys
  3. Upserts the record based on search keys
  4. Syncs any nested fixtures with the parent's ID

Summary

Functions

Delete records from the database that are not in the synced list.

Sync a fixture module's records to the database.

Sync a single record.

Sync records with a given config.

Types

sync_result()

@type sync_result() :: {:ok, struct() | [struct()]} | {:error, term()}

sync_result_with_pruned()

@type sync_result_with_pruned() ::
  {:ok, struct() | [struct()], deleted :: [struct()]} | {:error, term()}

Functions

prune(synced_records, config, repo)

Delete records from the database that are not in the synced list.

sync(fixture_module, repo, opts \\ [])

Sync a fixture module's records to the database.

Options

  • :prune - if true, deletes records not in fixtures. Defaults to false.

Returns

  • {:ok, synced_records} - when prune is false
  • {:ok, synced_records, deleted_records} - when prune is true
  • {:error, reason} - on failure

sync_record(record, config, repo)

@spec sync_record(map(), Sow.Config.t(), module()) ::
  {:ok, struct()} | {:error, term()}

Sync a single record.

sync_records(records, config, repo)

@spec sync_records(map() | [map()], Sow.Config.t(), module()) :: sync_result()

Sync records with a given config.