Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline live resource generation by inspecting the resource Ecto schema #696

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

tmbb
Copy link

@tmbb tmbb commented Dec 11, 2024

Introspect the ecto schema and automatically inflect the schema name to infer the singular name, plural name and the pubsub event name. The following exmaple is copied from the @moduledoc. This makes it very succint to use Backpex to add an admin layer to a number of Ecto schemas with very little code.

To use this functionality in your app, first define a new module in your application which encapsulates data that is common to all resources (repo, pubsub and layouts)

defmodule MyAppWeb.LiveResource do
  use Backpex.AutoLiveResource,
    repo: MyApp.Repo,
    layout: {MyAppWeb.Layouts, :admin},
    pubsub: MyApp.PubSub
end

Now, you can define a new live resource using the module above

defmodule MyAppWeb.MyResourceLive do
  use MyAppWeb.LiveResource,
    resource: MyApp.MyContext.MyResource
end

There are currently no integration tests for this (but then again, there are no integration tests for the rest of Backpex).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant