-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add support for DATABASE_URL
#559
Add support for DATABASE_URL
#559
Conversation
src/masoniteorm/config.py
Outdated
# this is a special case, because if we pass this URL into | ||
# urlparse, urlparse will choke trying to interpret "memory" | ||
# as a port number | ||
if url == "sqlite://:memory:": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably check for a couple of string here. Maybe also just :memory:
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nobody is going to remember this string without referring to the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we could check just :memory:
. What do you mean by couple of strings lol ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if url in ("sqlite://:memory:", ":memory:")
I am also assuming that sqlite://:memory:
is the officially supported string. I just want to be able to remember a string and I'm not going to remember sqlite://:memory:
lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll forget one of the 3 :
and pull my hair out why its not working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay got it. Actually you can already go the simple waysqlite://
but I can add sqlite://memory
also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you can use those for SQLite in memory:
db_url("sqlite://")
db_url("sqlite://memory")
db_url("sqlite://:memory:") # the official one
And for a SQLite classic db file:
db_url("sqlite://orm.sqlite3")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Great implementation
Unit tests have been added ✅ ! |
Fix #307.
Here is a proposal for supporting
DATABASE_URL
:Import the helper
This helper will return a full config dict that you can directly use in
DATABASES
config:Here as no url string is given it will automatically use
DATABASE_URL
env (as often exposed by PaaS service: Heroku...)You want to use an other env variable ? No problem:
Of course you can specify an url directly:
...and you can specify additional parameters:
...or you can just merge it with some other options (not related to the url):
It support all drivers.
For SQLite it's:
🎉 🚀
If it's okay, then I could add some unit tests.