Sorcery.StoreAdapter behaviour (sorcery v0.4.15)

A store adapter is a module that allows a PortalServer to access a data store by taking SrcQL, and converting it into something compatible with the specific store.

Currently there are only two Adapters available: Ecto, and InMemory. InMemory is used behind the scenes by the LiveHelper, and is basically a noop, preferring to keep all data in the portal itself. While the Sorcery.StoreAdapter.Ecto adapter is used for dealing with serious backends like MySql and Postgres.

Summary

Callbacks

run_mutation(sorcery_state, mutation)

@callback run_mutation(
  sorcery_state :: %Sorcery.PortalServer.InnerState{
    args: term(),
    config_module: term(),
    has_loaded?: term(),
    pending_portals: term(),
    portals: term(),
    store_adapter: term()
  },
  mutation ::
    %Sorcery.Mutation.ParentMutation{
      deletes: term(),
      inserts: term(),
      old_data: term(),
      updates: term(),
      version: term()
    }
    | %Sorcery.Mutation.ChildrenMutation{
        deletes: term(),
        inserts: term(),
        old_data: term(),
        updates: term(),
        version: term()
      }
) :: {:ok, %{updates: map(), inserts: map(), deletes: map()}} | {:error, any()}

run_query(sorcery_state, where_clauses, finds)

@callback run_query(
  sorcery_state :: %Sorcery.PortalServer.InnerState{
    args: term(),
    config_module: term(),
    has_loaded?: term(),
    pending_portals: term(),
    portals: term(),
    store_adapter: term()
  },
  where_clauses :: [
    %Sorcery.Query.WhereClause{
      arg_name: term(),
      attr: term(),
      left: term(),
      lvar: term(),
      op: term(),
      other_lvar: term(),
      other_lvar_attr: term(),
      right: term(),
      right_type: term(),
      tk: term()
    }
  ],
  finds :: map()
) ::
  {:ok,
   %Sorcery.ReturnedEntities{
     data: term(),
     lvar_tks: term(),
     primary_entities: term()
   }}
  | {:error, any()}

Functions

mutation(mod, state, mutation)

query(mod, state, clauses, finds)