{"id":26958558,"url":"https://github.com/mbuffa/confeature","last_synced_at":"2025-04-03T04:20:01.462Z","repository":{"id":60713566,"uuid":"524444141","full_name":"mbuffa/confeature","owner":"mbuffa","description":"Store strongly typed application-wide settings using Ecto and your caching strategy.","archived":false,"fork":false,"pushed_at":"2024-07-15T21:30:26.000Z","size":42,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T15:17:44.702Z","etag":null,"topics":["ecto","elixir"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbuffa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-13T15:59:04.000Z","updated_at":"2024-07-01T07:36:49.000Z","dependencies_parsed_at":"2022-10-03T16:16:34.986Z","dependency_job_id":null,"html_url":"https://github.com/mbuffa/confeature","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuffa%2Fconfeature","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuffa%2Fconfeature/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuffa%2Fconfeature/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuffa%2Fconfeature/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbuffa","download_url":"https://codeload.github.com/mbuffa/confeature/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246847137,"owners_count":20843444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecto","elixir"],"created_at":"2025-04-03T04:20:00.809Z","updated_at":"2025-04-03T04:20:01.447Z","avatar_url":"https://github.com/mbuffa.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Confeature\n\n`Confeature` is a generic and simple Elixir library to handle your application-wide feature settings, storing them with Ecto and providing a cache interface.\n\nPlease note that this is a very early development, and that `Confeature` hasn't been tested a lot in production yet.\n\nAlso, if you're looking for feature flags that you may apply on groups or actors, you should definitely use `:fun_with_flags` instead.\n\nThe scope of `Confeature` is primarily set on:\n* Allowing you to change your application settings dynamically,\n* Setting any value at runtime,\n* Type-checking updates with structs and specs.\n\n## Documentation\n\nDocumentation is available on [https://hexdocs.pm/confeature](https://hexdocs.pm/confeature).\n\n## Installation\n\nAdd `confeature` to your dependencies:\n```elixir\ndef deps do\n  [\n    {:confeature, \"~\u003e 0.1.1\"}\n  ]\nend\n```\n\n## Usage\n\nStart by creating Confeature table:\n```sh\nmix ecto.gen.migration create_confeature_table\n```\n\nAnd use Confeature provided migration:\n```elixir\ndefmodule YourEctoMigration do\n  def up do\n    Confeature.Migration.up()\n    # or optionally:\n    Confeature.Migration.up(table_name: \"my_features\")\n  end\n\n  def down do\n    Confeature.Migration.down()\n    # or optionally:\n    Confeature.Migration.down(table_name: \"my_features\")\n  end\nend\n```\n\nDeclare your Confeature interface\n```elixir\ndefmodule MyApp.Confeature do\n  use Confeature,\n    ecto_repo: MyApp.Repo,\n    table_name: \"my_features\", # Optional\n    cache: MyApp.Cache.Feature # Optional\nend\n```\nYou can check the documentation for implementing a cache store that'll avoid querying your database on each call.\n\nThen, declare a feature, like this:\n```elixir\ndefmodule MyApp.Features.Throttling do\n  defstruct [:identifier, :threshold]\n\n  @type t :: %__MODULE__{\n    identifier: string(),\n    threshold: integer()\n  }\nend\n```\n\nLet's say that you'd want to initialize it in an Ecto migration:\n```sh\nmix ecto.gen.migration init_throttling_settings\n```\n\n```elixir\ndefmodule YourMigration do\n  def up do\n    MyApp.Confeature.set(%MyApp.Features.Throttling{\n      identifier: \"token\",\n      threshold: 500 # 500 requests\n    })\n  end\n\n  def down do\n    MyApp.Confeature.delete!(MyApp.Features.Throttling)\n  end\nend\n```\n\nYou can then reference it in your code:\n```elixir\n# Retrieve settings\niex\u003e MyApp.Confeature.get(MyApp.Features.Throttling)\n%MyApp.Features.Throttling{identifier: \"token\", threshold: 500}\n\niex\u003e MyApp.Confeature.set(%MyApp.Features.Throttlin{identifier: \"token\", threshold: 1000})\n%MyApp.Features.Throttling{identifier: \"token\", threshold: 1000}\n```\n\nConfeature upserts one row per feature in your RDBMS, using a json field to store attributes.\n\nYou can also declare a `:enabled` attribute, so your feature can be enabled and disabled at runtime:\n```elixir\ndefmodule MyApp.Features.Throttling do\n  defstruct [:enabled, :identifier, :threshold]\n\n  @type t :: %__MODULE__{\n    enabled: boolean(),\n    identifier: string(),\n    threshold: integer()\n  }\nend\n\nMyApp.Confeature.enabled?(MyApp.Features.Throttling) \nMyApp.Confeature.enable(MyApp.Features.Throttling) \nMyApp.Confeature.disable(MyApp.Features.Throttling) \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbuffa%2Fconfeature","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbuffa%2Fconfeature","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbuffa%2Fconfeature/lists"}