Open ZeroIntensity opened 10 months ago
Hey! I would like to work on this. Even though i have worked with sqlite and orms in flask and django, I don't know how they are working/connected. Could you please elaborate on what exactly do you want?
I was thinking it could be a system that wraps several different databases into one API. For building this, you would need to design a driver for each database.
Ideally, it should look like this:
@model()
class User:
name: str
async for user in User.many(): # fetch all users
...
zero = await User.fetch(name="ZeroIntensity")
await User(name="test").save()
The above code would work with any database that the user selects. I was planning on supporting the following:
I think support for Redis caching could also be done, but that's for a future issue.
On the backend, driving each database should look something like this:
class _MongoDriver(_Driver):
... # code specific to mongodb
class _PostgresDriver(_Driver):
... # code specific to postgres
class _Connection:
def __init__(self, driver: _Driver): # this can take in any driver
...
Then, models can use a global _Connection
instance to access the db.
Note that implementing each database protocol is probably unnecessary, and instead we should just use libraries that already exist to drive each database (i.e. PyMongo for MongoDB).
Also, #9 needs to be finished before this can really get going. It's almost done (see this branch), but it's untested and probably a bit buggy so far.
Ok, I will see what can I do till you get #9 merged
Just to inform, I am working on this issue...this stuff is a bit new so I am researching and hence may take some time. But I am working on it
I have created a new folder named database and creating database related files in it. But how do I use it like i use views? It is showing no module named database even after I build it (pip install .)
Python code should go in the view
folder, not src. I would actually rather you not use a folder, and instead just put it in databases.py
. I think codebase sorts of questions should go into the discord from now on, GitHub isn't really for debugging.
Enough of this has been done to mark it as "not hot"
For batteries detachable purposes, the Django ORM, PeeWee, and probably SQLAlchemy should all be supported natively by view.py
SQLModel looks like a good choice to support as well.
Waiting on #9, probably. Should probably support SQLite first.
Hypothetical API: