Comments (11)
token_source
would be a function to load the table name, for example:
defp token_source() do
Application.fetch_env!(:guardian_db, GuardianDb)
|> Keyword.get(:schema_name, "guardian_tokens")
end
This isn't documented anywhere in one place, unfortunately. Some bits are in the Ecto.Schema
docs, some in Ecto.Query
and some in Ecto
. This would use the same technique as the one described in the polymorphic belongs_to docs.
from guardian_db.
I opened a PR to ecto with improvements to the docs around the __meta__
field: elixir-ecto/ecto#2228
from guardian_db.
It seems that the error was because I had changed the schema_name
value without recompiling the dependencies. I'll submit a PR to add a note about this to the documentation.
from guardian_db.
@davejlong the correct solution for this is to change
guardian_db/lib/guardian_db.ex
Line 128 in 496384d
Talking to Michal about it, use module attributes for reading this configurations is a bad practice because of the situation you ran into, which is pretty common to run into
from guardian_db.
hhhhmmm I think I can't switch it to some function call 😢 so it will be better to actually add some documentation I think
from guardian_db.
Ecto supports using {"table_name", Schema}
as the source of a query. This can be leveraged by changing, for example:
guardian_db/lib/guardian_db.ex
Line 149 in 496384d
to
GuardianDb.repo.get_by({token_source(), Token}, jti: jti, aud: aud)
It's also supported when creating structs like here:
guardian_db/lib/guardian_db.ex
Lines 161 to 163 in 496384d
which could be replaced by:
%Token{}
|> Ecto.put_meta(source: token_source())
#...
Ecto makes sure that structs extracted from tagged queries when used with update
or delete
issue correct queries.
This should cover all the use cases.
from guardian_db.
@michalmuskala what is that token_source
the schema_name
in this case? What about the schema "name over here"
situation?
Could you point me to the doc spot so I can read about it please
from guardian_db.
@michalmuskala I notice this https://github.com/elixir-ecto/ecto/blob/v2.2.3/lib/ecto/schema.ex#L378 if I use embedded_schema
I dont need any random name on the schema
name because I will be using what you recommend.
What are your thoughts about it?
from guardian_db.
embedded_schema
generates a slightly different struct from schema
- in particular, it doesn't track the lifetime of the struct (since it doesn't matter for embedded associations). The difference is the __meta__
key.
from guardian_db.
@michalmuskala wouldn't be worth to add the differences in Ecto documentation?
Situation like this one people dont have to ask you what the differences are and it's important to know for apply the correct use of it.
For example right now, I don't know what you meant by lifetime
of the struct and other situations.
What do you think?
from guardian_db.
@michalmuskala you are the boss!
from guardian_db.
Related Issues (20)
- separated token schemes HOT 4
- hash of tokens HOT 2
- Revoking Token thats already been removed throws error rather than returning error HOT 1
- Dependency Update
- Changelog updates since 0.8 HOT 3
- How to add more columns to 'guardian_tokens' table? HOT 5
- Compatibility with Guardian 2.0 HOT 2
- Idea: Use gen server to avoid round-trip to database HOT 9
- Update ecto_sql(currently at 3.1.0) dependency to the latest version HOT 1
- Do not fix ecto version HOT 2
- Documentation: need to update migrations if using non-default table name
- Guardian DB Redis Repo HOT 11
- Ecto.StaleEntryError when using Guardian.DB.on_revoke HOT 8
- cut a new release? HOT 1
- Add a column to optionally store the jti of the refresh token used to generate an access token. HOT 2
- Publish new release HOT 1
- `Guardian.DB.Sweeper` incompatible with old worker API HOT 1
- function Guardian.DB.on_refresh/2 is undefined or private HOT 3
- guardian_db fails to compile with Ecto 3 rc (undefined function migrations_path/1) HOT 20
- how to use in two or more servers with login just one time? share pwd HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guardian_db.