예제 #1
0
    def get_builder(self):
        from config.database import DB

        connection = self.__connection__

        if connection == "default":
            connection = DB.get_connection_details().get("default")

        connection_driver = (DB.get_connection_details().get(connection,
                                                             {}).get("driver"))
        self.__resolved_connection__ = DB.connection_factory.make(
            connection_driver)
        self.builder = QueryBuilder(
            # grammar=self.__resolved_connection__.get_default_query_grammar(),
            connection=self.__connection__,
            # connection_class=self.__resolved_connection__,
            table=self.get_table_name(),
            connection_details=self.get_connection_details(),
            model=self,
            # connection_driver=connection_driver,
            scopes=self._scopes,
            dry=self.__dry__,
        )

        return self.builder
예제 #2
0
파일: Migration.py 프로젝트: circulon/orm
    def __init__(
        self,
        connection="default",
        dry=False,
        command_class=None,
        migration_directory="databases/migrations",
    ):
        self.connection = connection
        self.migration_directory = migration_directory.replace("/", ".")
        self.last_migrations_ran = []
        self.command_class = command_class

        from config.database import DB

        DATABASES = DB.get_connection_details()

        self.schema = Schema(connection=connection,
                             connection_details=DATABASES,
                             dry=dry)

        self.migration_model = MigrationModel.on(self.connection)
예제 #3
0
    def __init__(
        self,
        grammar=None,
        connection="default",
        connection_class=None,
        table=None,
        connection_details={},
        connection_driver="default",
        model=None,
        scopes={},
        dry=False,
    ):
        """QueryBuilder initializer

        Arguments:
            grammar {masonite.orm.grammar.Grammar} -- A grammar class.

        Keyword Arguments:
            connection {masonite.orm.connection.Connection} -- A connection class (default: {None})
            table {str} -- the name of the table (default: {""})
        """
        self.grammar = grammar
        self._table = table
        self.dry = dry
        self.connection = connection
        self.connection_class = connection_class
        self._connection = None
        self._connection_details = connection_details
        self._connection_driver = connection_driver
        self._scopes = scopes
        self._eager_relation = EagerRelations()
        if model:
            self._global_scopes = model._global_scopes
            if model.__with__:
                self.with_(model.__with__)
        else:
            self._global_scopes = {}

        self.builder = self

        self._columns = ()
        self._creates = {}

        self._sql = ""
        self._sql_binding = ""
        self._bindings = ()

        self._updates = ()

        self._wheres = ()
        self._order_by = ()
        self._group_by = ()
        self._joins = ()
        self._having = ()
        self._macros = {}

        self._aggregates = ()

        self._limit = False
        self._offset = False
        self._model = model
        self.set_action("select")

        if not self._connection_details:
            from config.database import DB

            self._connection_details = DB.get_connection_details()

        self.on(connection)

        if grammar:
            self.grammar = grammar

        if connection_class:
            self.connection_class = connection_class