Skip to content

QueryBuilder should use get_connection() not new_connection() internally #960

@circulon

Description

@circulon

Describe the bug
Like #958 the QueryBuilder class creates a new connection object for many calls to the backend.
Ideally the new_connection() method should only return (not store) the connection object and the get_connection() method should be used to manage the internal _commection instance var.

To Reproduce
see this code:

    def new_connection(self):
        if self._connection:
            return self._connection

        self._connection = (
            self.connection_class(
                **self.get_connection_information(), name=self.connection
            )
            .set_schema(self._schema)
            .make_connection()
        )
        return self._connection

    def get_connection(self):
        return self._connection

Expected behavior
get_connection() should be used internally (possibly elsewhere as well)
so connections are not made to the backend unneccarily.

Screenshots or code snippets
N/A

Desktop (please complete the following information):

  • OS: MacOS
  • Version 12.7 Monterey

What database are you using?

  • Type: Postgres, MySQL, SQLite
  • Version any
  • Masonite ORM: latest 2.0 and latest 3.0 (latest 3.x branch)

Additional context
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn existing feature is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions