Skip to content
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

Support read and write connection #308

Open
josephmancuso opened this issue Jan 11, 2021 · 2 comments
Open

Support read and write connection #308

josephmancuso opened this issue Jan 11, 2021 · 2 comments
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before Query Builder Related to the query builder Schema Related to the schema builder

Comments

@josephmancuso
Copy link
Member

Should be of lower priority but we should be able to support read and write connections. These should be set on the connection driver.

We will need to specify these in the query builder when creating the connection class as well as the schema class. But we should only specify it in those 2 classes so it should not be a big issue adding this.

The connection details should look something like this:

    'mysql': {
        'read': {
            'host': '192.168.1.1'
        },
        'write': {
            'host': '192.168.1.2'
        },
        'driver': 'mysql',
        'database': 'database',
        'username': 'root',
       ...

Anything inside those read and write configs should override the other configs.

When creating the connection class we will need to fetch this information properly and pass it to the connection class

@josephmancuso josephmancuso added Query Builder Related to the query builder Schema Related to the schema builder medium These issues are geared for people who have contributed to the project before feature request A feature that does not yet exist but will be a good addition to the library labels Jan 11, 2021
@girardinsamuel
Copy link
Contributor

girardinsamuel commented Jan 14, 2021

I am not sure of understanding the use case here ? Is it for example to be able to read from a database server 1 and to write on an other database server 2 ?

@josephmancuso
Copy link
Member Author

josephmancuso commented Jan 14, 2021

@girardinsamuel Yes exactly. I haven't personally seen a need for that and I've built lots of applications both personally, for clients and for businesses but its a feature in Orator and Laravel's Eloquent and it would be fairly simple to do.

The only trick, and another requirement for this, is to make a sticky option which is a read and write to the same connection within the same request.

So in other words we would need to be able to support something like this:

# Sticky: False
User.create({}) # .. write to 192.168.1.1
User.all() # .. read from 192.168.1.2

But we need to support a sticky options where it will read to the server it just wrote to.

# Sticky: True
# First request
User.create({}) # .. write to 192.168.1.1
User.all() # .. read from 192.168.1.1
# Sticky: True
# Second request
User.all() # .. read from 192.168.1.2

If that make sense. A lot of people will create this second database server only for reads or only for writes which increases performance. But when they write to one of the database servers its not going to be available in the read database server so they need to read from the database server they just wrote to but only for that request cycle.

I've been giving some thought over last few days and really not sure how we will do the sticky option here .. somehow we need to tie an encoded request string like RQyugshajq81 to a specific request connection maybe and then store and fetch from the StickyRequestConnection class maybe. This ORM obviously needs to work outside of a request life cycle. This ORM needs to work in somebodies simple python file.

Orator does not have this sticky option I believe so we will need to come up with our own solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before Query Builder Related to the query builder Schema Related to the schema builder
Projects
None yet
Development

No branches or pull requests

2 participants