Giter Club home page Giter Club logo

Comments (11)

aleDsz avatar aleDsz commented on July 19, 2024 1

I was thinking about this API

defmodule Guardian.DB.Adapter do
  @moduledoc """
  The Guardian DB Adapter.

  This behaviour allows to use any storage system
  for Guardian Tokens.
  """

  @typep query :: Ecto.Query.t()
  @typep schema :: Ecto.Schema.t()
  @typep schema_or_changeset :: schema() | Ecto.Changeset.t()
  @typep queryable :: query() | schema()
  @typep opts :: keyword()
  @typep id :: pos_integer() | binary() | Ecto.UUID.t()

  @callback one(queryable()) :: nil | schema()
  @callback get(queryable(), id()) :: nil | schema()
  @callback insert(schema_or_changeset()) :: {:ok, schema()}
  @callback delete(schema_or_changeset()) :: {:ok, schema()}
  @callback delete_all(queryable()) :: {:ok, pos_integer()}
  @callback delete_all(queryable(), opts()) :: {:ok, pos_integer()}
end

@alexfilatov do you think it's enough to bring Redis, or any storage adapter to Guardian.DB?

from guardian_db.

doomspork avatar doomspork commented on July 19, 2024 1

This is a great idea! @alexfilatov if you want to open a draft PR to solicit feedback feel free 👍

from guardian_db.

alexfilatov avatar alexfilatov commented on July 19, 2024 1

Hello there again @doomspork and @aleDsz!

Sorry for the long reply, got back to this one eventually.

I got a slightly different idea.
I started working on the PR for guardian_db but one thing was very annoying for me - why would guardian_db have some new dependencies (on redix and jason) just because of a new Redis repo? What if the user will not use Redis as storage for tokens but still have those dependencies?
Also, I read a great article from @savonarola about SOLID principles in Elixir and that was literally my case!

So I started working on https://github.com/alexfilatov/guardian_redis - a plugin for guardian_db. The only thing user need to do is to include this library in deps and change repo settings (well, Redis settings as well, but this goes without saying:)

This is still a Work in Progress but I would like to hear your early feedback, please.

from guardian_db.

yordis avatar yordis commented on July 19, 2024 1

@alexfilatov I forgot about something, I only see {:ok, ....} success responses in the callback, is that correct? or do we need some error tuple response as well?

from guardian_db.

aleDsz avatar aleDsz commented on July 19, 2024

I think it's a good idea, and we can improve that using an Adapter for token storage, using the same @behaviour to allow users to change to their preference, and ur repo can become and plugin adapter for Redis.

What u think?

from guardian_db.

yordis avatar yordis commented on July 19, 2024

@alexfilatov welcome to add some adapter pattern around GuardianDB, make sure to tag me on it ... I keep losing notifications, I will help you to review and merge it

from guardian_db.

alexfilatov avatar alexfilatov commented on July 19, 2024

love it @aleDsz, will work on PR asap, will let you guy know when ready!

from guardian_db.

aleDsz avatar aleDsz commented on July 19, 2024

@alexfilatov i can help if u want to. I was thinking about to ask your help to make a good integration using this behaviour to test the idea and checking if it would work with Ecto and Redix

from guardian_db.

alexfilatov avatar alexfilatov commented on July 19, 2024

this one solved by adding an adapter here #126 and implementing a Redis plugin https://github.com/alexfilatov/guardian_redis

from guardian_db.

alexfilatov avatar alexfilatov commented on July 19, 2024

this is a great catch @yordis! yes, we need {:error, ... } as well, e.g.

@callback insert(schema_or_changeset()) :: {:ok, schema()} | {:error, Ecto.Changeset.t()}

Will prepare new PR.

from guardian_db.

alexfilatov avatar alexfilatov commented on July 19, 2024

Hey @yordis, made a PR, could you please have a look? ^^

from guardian_db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.