INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Merge the "wheres" from a relation query to a has query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.relations.Relation
def _merge_model_defined_relation_wheres_to_has_query(self, has_query, relation): """ Merge the "wheres" from a relation query to a has query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.rela...
Set the relationships that should be eager loaded. :return: The current Builder instance :rtype: Builder
def with_(self, *relations): """ Set the relationships that should be eager loaded. :return: The current Builder instance :rtype: Builder """ if not relations: return self eagers = self._parse_with_relations(list(relations)) self._eager_load...
Parse a list of relations into individuals. :param relations: The relation to parse :type relations: list :rtype: dict
def _parse_with_relations(self, relations): """ Parse a list of relations into individuals. :param relations: The relation to parse :type relations: list :rtype: dict """ results = {} for relation in relations: if isinstance(relation, dict):...
Call the given model scope. :param scope: The scope to call :type scope: str
def _call_scope(self, scope, *args, **kwargs): """ Call the given model scope. :param scope: The scope to call :type scope: str """ query = self.get_query() # We will keep track of how many wheres are on the query before running the # scope so that we ca...
Get the underlying query builder instance with applied global scopes. :type: Builder
def apply_scopes(self): """ Get the underlying query builder instance with applied global scopes. :type: Builder """ if not self._scopes: return self builder = copy.copy(self) query = builder.get_query() # We will keep track of how many whe...
Apply a single scope on the given builder instance. :param scope: The scope to apply :type scope: callable or Scope :param builder: The builder to apply the scope to :type builder: Builder
def _apply_scope(self, scope, builder): """ Apply a single scope on the given builder instance. :param scope: The scope to apply :type scope: callable or Scope :param builder: The builder to apply the scope to :type builder: Builder """ if callable(scope...
Nest where conditions of the builder and each global scope. :type query: QueryBuilder :type where_counts: list
def _nest_wheres_for_scope(self, query, where_counts): """ Nest where conditions of the builder and each global scope. :type query: QueryBuilder :type where_counts: list """ # Here, we totally remove all of the where clauses since we are going to # rebuild them a...
Create a where list with sliced where conditions. :type wheres: list :type offset: int :type length: int :rtype: list
def _slice_where_conditions(self, wheres, offset, length): """ Create a where list with sliced where conditions. :type wheres: list :type offset: int :type length: int :rtype: list """ where_group = self.get_query().for_nested_where() where_group...
Set a model instance for the model being queried. :param model: The model instance :type model: orator.orm.Model :return: The current Builder instance :rtype: Builder
def set_model(self, model): """ Set a model instance for the model being queried. :param model: The model instance :type model: orator.orm.Model :return: The current Builder instance :rtype: Builder """ self._model = model self._query.from_(mode...
Compile insert statement into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :param values: The insert values :type values: dict or list :return: The compiled insert :rtype: str
def compile_insert(self, query, values): """ Compile insert statement into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :param values: The insert values :type values: dict or list :return: The compiled insert :rtype: str "...
Compile a truncate statement into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :return: The compiled truncate statement :rtype: str
def compile_truncate(self, query): """ Compile a truncate statement into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :return: The compiled truncate statement :rtype: str """ sql = { "DELETE FROM sqlite_sequence WHERE n...
Execute the blueprint against the database. :param connection: The connection to use :type connection: orator.connections.Connection :param grammar: The grammar to user :type grammar: orator.query.grammars.QueryGrammar
def build(self, connection, grammar): """ Execute the blueprint against the database. :param connection: The connection to use :type connection: orator.connections.Connection :param grammar: The grammar to user :type grammar: orator.query.grammars.QueryGrammar "...
Get the raw SQL statements for the blueprint. :param connection: The connection to use :type connection: orator.connections.Connection :param grammar: The grammar to user :type grammar: orator.schema.grammars.SchemaGrammar :rtype: list
def to_sql(self, connection, grammar): """ Get the raw SQL statements for the blueprint. :param connection: The connection to use :type connection: orator.connections.Connection :param grammar: The grammar to user :type grammar: orator.schema.grammars.SchemaGrammar ...
Add the commands that are implied by the blueprint.
def _add_implied_commands(self): """ Add the commands that are implied by the blueprint. """ if len(self.get_added_columns()) and not self._creating(): self._commands.insert(0, self._create_command("add")) if len(self.get_changed_columns()) and not self._creating(): ...
Indicates that the given columns should be dropped. :param columns: The columns to drop :type columns: tuple :rtype: Fluent
def drop_column(self, *columns): """ Indicates that the given columns should be dropped. :param columns: The columns to drop :type columns: tuple :rtype: Fluent """ columns = list(columns) return self._add_command("drop_column", columns=columns)
Create a new integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent
def integer(self, column, auto_increment=False, unsigned=False): """ Create a new integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent """ return self._add_colum...
Create a new small integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent
def small_integer(self, column, auto_increment=False, unsigned=False): """ Create a new small integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent """ return sel...
Create a new unisgned integer column on the table. :param column: The column :type column: str :type auto_increment: bool :rtype: Fluent
def unsigned_integer(self, column, auto_increment=False): """ Create a new unisgned integer column on the table. :param column: The column :type column: str :type auto_increment: bool :rtype: Fluent """ return self.integer(column, auto_increment, True)
Create a new unsigned big integer column on the table. :param column: The column :type column: str :type auto_increment: bool :rtype: Fluent
def unsigned_big_integer(self, column, auto_increment=False): """ Create a new unsigned big integer column on the table. :param column: The column :type column: str :type auto_increment: bool :rtype: Fluent """ return self.big_integer(column, auto_incre...
Create a new float column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent
def float(self, column, total=8, places=2): """ Create a new float column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent """ return self._add_column("float", column, total=total, places...
Create a new double column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent
def double(self, column, total=None, places=None): """ Create a new double column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent """ return self._add_column("double", column, total=tota...
Create a new decimal column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent
def decimal(self, column, total=8, places=2): """ Create a new decimal column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent """ return self._add_column("decimal", column, total=total, ...
Create creation and update timestamps to the table. :rtype: Fluent
def timestamps(self, use_current=True): """ Create creation and update timestamps to the table. :rtype: Fluent """ if use_current: self.timestamp("created_at").use_current() self.timestamp("updated_at").use_current() else: self.timesta...
Add the proper columns for a polymorphic table. :type name: str :type index_name: str
def morphs(self, name, index_name=None): """ Add the proper columns for a polymorphic table. :type name: str :type index_name: str """ self.unsigned_integer("%s_id" % name) self.string("%s_type" % name) self.index(["%s_id" % name, "%s_type" % name], inde...
Create a new drop index command on the blueprint. :param command: The command :type command: str :param type: The index type :type type: str :param index: The index name :type index: str :rtype: Fluent
def _drop_index_command(self, command, type, index): """ Create a new drop index command on the blueprint. :param command: The command :type command: str :param type: The index type :type type: str :param index: The index name :type index: str ...
Add a new index command to the blueprint. :param type: The index type :type type: str :param columns: The index columns :type columns: list or str :param index: The index name :type index: str :rtype: Fluent
def _index_command(self, type, columns, index): """ Add a new index command to the blueprint. :param type: The index type :type type: str :param columns: The index columns :type columns: list or str :param index: The index name :type index: str ...
Removes a column from the blueprint. :param name: The column name :type name: str :rtype: Blueprint
def _remove_column(self, name): """ Removes a column from the blueprint. :param name: The column name :type name: str :rtype: Blueprint """ self._columns = filter(lambda c: c.name != name, self._columns) return self
Add a new command to the blueprint. :param name: The command name :type name: str :param parameters: The command parameters :type parameters: dict :rtype: Fluent
def _add_command(self, name, **parameters): """ Add a new command to the blueprint. :param name: The command name :type name: str :param parameters: The command parameters :type parameters: dict :rtype: Fluent """ command = self._create_command(...
Returns the quoted representation of the column names the constraint is associated with. But only if they were defined with one or a column name is a keyword reserved by the platform. Otherwise the plain unquoted value as inserted is returned. :param platform: The platform to u...
def get_quoted_columns(self, platform): """ Returns the quoted representation of the column names the constraint is associated with. But only if they were defined with one or a column name is a keyword reserved by the platform. Otherwise the plain unquoted value as inser...
:type column_name: str :type pos: int :rtype: bool
def has_column_at_position(self, column_name, pos=0): """ :type column_name: str :type pos: int :rtype: bool """ column_name = self._trim_quotes(column_name.lower()) index_columns = [c.lower() for c in self.get_unquoted_columns()] return index_columns.in...
Checks if this index exactly spans the given column names in the correct order. :type column_names: list :rtype: bool
def spans_columns(self, column_names): """ Checks if this index exactly spans the given column names in the correct order. :type column_names: list :rtype: bool """ columns = self.get_columns() number_of_columns = len(columns) same_columns = True ...
Checks if the other index already fulfills all the indexing and constraint needs of the current one. :param other: The other index :type other: Index :rtype: bool
def is_fullfilled_by(self, other): """ Checks if the other index already fulfills all the indexing and constraint needs of the current one. :param other: The other index :type other: Index :rtype: bool """ # allow the other index to be equally large only...
Return whether the two indexes have the same partial index :param other: The other index :type other: Index :rtype: bool
def same_partial_index(self, other): """ Return whether the two indexes have the same partial index :param other: The other index :type other: Index :rtype: bool """ if ( self.has_option("where") and other.has_option("where") ...
Detects if the other index is a non-unique, non primary index that can be overwritten by this one. :param other: The other index :type other: Index :rtype: bool
def overrules(self, other): """ Detects if the other index is a non-unique, non primary index that can be overwritten by this one. :param other: The other index :type other: Index :rtype: bool """ if other.is_primary(): return False e...
Removes a flag. :type flag: str
def remove_flag(self, flag): """ Removes a flag. :type flag: str """ if self.has_flag(flag): del self._flags[flag.lower()]
Get the current page for the request. :param current_page: The current page of results :type current_page: int :param last_page: The last page of results :type last_page: int :rtype: int
def _set_current_page(self, current_page, last_page): """ Get the current page for the request. :param current_page: The current page of results :type current_page: int :param last_page: The last page of results :type last_page: int :rtype: int """ ...
Compile a create table command.
def compile_create(self, blueprint, command, connection): """ Compile a create table command. """ columns = ", ".join(self._get_columns(blueprint)) sql = "CREATE TABLE %s (%s)" % (self.wrap_table(blueprint), columns) sql = self._compile_create_encoding(sql, connection, ...
Append the character set specifications to a command. :type sql: str :type connection: orator.connections.Connection :type blueprint: Blueprint :rtype: str
def _compile_create_encoding(self, sql, connection, blueprint): """ Append the character set specifications to a command. :type sql: str :type connection: orator.connections.Connection :type blueprint: Blueprint :rtype: str """ charset = blueprint.charse...
Get the column change options.
def _get_column_change_options(self, fluent): """ Get the column change options. """ options = super(MySQLSchemaGrammar, self)._get_column_change_options(fluent) if fluent.type == "enum": options["extra"] = { "definition": "('{}')".format("','".join(f...
Executes the command.
def handle(self): """ Executes the command. """ if not self.confirm_to_proceed( "<question>Are you sure you want to seed the database?:</question> " ): return self.resolver.set_default_connection(self.option("database")) self._get_seeder(...
Get the destination class path. :param name: The name :type name: str :rtype: str
def _get_path(self, name): """ Get the destination class path. :param name: The name :type name: str :rtype: str """ path = self.option("path") if path is None: path = self._get_seeders_path() return os.path.join(path, "%s.py" % name...
Set the base constraints of the relation query
def add_constraints(self): """ Set the base constraints of the relation query """ if self._constraints: self._query.where(self._foreign_key, "=", self.get_parent_key())
Set the constraints for an eager load of the relation. :type models: list
def add_eager_constraints(self, models): """ Set the constraints for an eager load of the relation. :type models: list """ return self._query.where_in( self._foreign_key, self.get_keys(models, self._local_key) )
Match the eargerly loaded resuls to their single parents. :param models: The parents :type models: list :param results: The results collection :type results: Collection :param relation: The relation :type relation: str :param type_: The match type :typ...
def _match_one_or_many(self, models, results, relation, type_): """ Match the eargerly loaded resuls to their single parents. :param models: The parents :type models: list :param results: The results collection :type results: Collection :param relation: The rel...
Attach a model instance to the parent models. :param model: The model instance to attach :type model: Model :rtype: Model
def save(self, model): """ Attach a model instance to the parent models. :param model: The model instance to attach :type model: Model :rtype: Model """ model.set_attribute(self.get_plain_foreign_key(), self.get_parent_key()) if model.save(): ...
Find a model by its primary key or return new instance of the related model. :param id: The primary key :type id: mixed :param columns: The columns to retrieve :type columns: list :rtype: Collection or Model
def find_or_new(self, id, columns=None): """ Find a model by its primary key or return new instance of the related model. :param id: The primary key :type id: mixed :param columns: The columns to retrieve :type columns: list :rtype: Collection or Model ...
Create or update a related record matching the attributes, and fill it with values. :param attributes: The attributes :type attributes: dict :param values: The values :type values: dict :rtype: Model
def update_or_create(self, attributes, values=None): """ Create or update a related record matching the attributes, and fill it with values. :param attributes: The attributes :type attributes: dict :param values: The values :type values: dict :rtype: Model ...
Create a new instance of the related model. :param attributes: The attributes :type attributes: dict :rtype: Model
def create(self, _attributes=None, **attributes): """ Create a new instance of the related model. :param attributes: The attributes :type attributes: dict :rtype: Model """ if _attributes is not None: attributes.update(_attributes) instance ...
Create a list of new instances of the related model. :param records: instances attributes :type records: list :rtype: list
def create_many(self, records): """ Create a list of new instances of the related model. :param records: instances attributes :type records: list :rtype: list """ instances = [] for record in records: instances.append(self.create(**record)) ...
Perform an update on all the related models. :param attributes: The attributes :type attributes: dict :rtype: int
def update(self, _attributes=None, **attributes): """ Perform an update on all the related models. :param attributes: The attributes :type attributes: dict :rtype: int """ if _attributes is not None: attributes.update(_attributes) if self._r...
Return the SQLAlchemy database dialect class corresponding to this URL's driver name.
def get_dialect(self): """Return the SQLAlchemy database dialect class corresponding to this URL's driver name. """ if "+" not in self.drivername: name = self.drivername else: name = self.drivername.replace("+", ".") cls = registry.load(name) ...
Translate url attributes into a dictionary of connection arguments. Returns attributes of this url (`host`, `database`, `username`, `password`, `port`) as a plain dictionary. The attribute names are used as the keys by default. Unset or false attributes are omitted from the final dict...
def translate_connect_args(self, names=[], **kw): """Translate url attributes into a dictionary of connection arguments. Returns attributes of this url (`host`, `database`, `username`, `password`, `port`) as a plain dictionary. The attribute names are used as the keys by default. Unse...
Obtains DBMS specific SQL code portion needed to set a CHECK constraint declaration to be used in statements like CREATE TABLE. :param definition: The check definition :type definition: dict :return: DBMS specific SQL code portion needed to set a CHECK constraint. :rtype: str
def get_check_declaration_sql(self, definition): """ Obtains DBMS specific SQL code portion needed to set a CHECK constraint declaration to be used in statements like CREATE TABLE. :param definition: The check definition :type definition: dict :return: DBMS specific SQL...
Obtains DBMS specific SQL code portion needed to set a unique constraint declaration to be used in statements like CREATE TABLE. :param name: The name of the unique constraint. :type name: str :param index: The index definition :type index: Index :return: DBMS specific...
def get_unique_constraint_declaration_sql(self, name, index): """ Obtains DBMS specific SQL code portion needed to set a unique constraint declaration to be used in statements like CREATE TABLE. :param name: The name of the unique constraint. :type name: str :param inde...
Obtains DBMS specific SQL code portion needed to set an index declaration to be used in statements like CREATE TABLE. :param name: The name of the index. :type name: str :param index: The index definition :type index: Index :return: DBMS specific SQL code portion neede...
def get_index_declaration_sql(self, name, index): """ Obtains DBMS specific SQL code portion needed to set an index declaration to be used in statements like CREATE TABLE. :param name: The name of the index. :type name: str :param index: The index definition :ty...
Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE. :param foreign_key: The foreign key :type foreign_key: ForeignKeyConstraint :rtype: str
def get_foreign_key_declaration_sql(self, foreign_key): """ Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE. :param foreign_key: The foreign key :type foreign_key: ForeignKeyConstrai...
Returns the FOREIGN KEY query section dealing with non-standard options as MATCH, INITIALLY DEFERRED, ON UPDATE, ... :param foreign_key: The foreign key :type foreign_key: ForeignKeyConstraint :rtype: str
def get_advanced_foreign_key_options_sql(self, foreign_key): """ Returns the FOREIGN KEY query section dealing with non-standard options as MATCH, INITIALLY DEFERRED, ON UPDATE, ... :param foreign_key: The foreign key :type foreign_key: ForeignKeyConstraint :rtype: str ...
Returns the given referential action in uppercase if valid, otherwise throws an exception. :param action: The action :type action: str :rtype: str
def get_foreign_key_referential_action_sql(self, action): """ Returns the given referential action in uppercase if valid, otherwise throws an exception. :param action: The action :type action: str :rtype: str """ action = action.upper() if action not in ...
Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE. :param foreign_key: The foreign key :type foreign_key: ForeignKeyConstraint :rtype: str
def get_foreign_key_base_declaration_sql(self, foreign_key): """ Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE. :param foreign_key: The foreign key :type foreign_key: ForeignKeyCo...
Gets declaration of a number of fields in bulk.
def get_column_declaration_list_sql(self, fields): """ Gets declaration of a number of fields in bulk. """ query_fields = [] for name, field in fields.items(): query_fields.append(self.get_column_declaration_sql(name, field)) return ", ".join(query_fields)
Obtains DBMS specific SQL code portion needed to set an index declaration to be used in statements like CREATE TABLE. :param fields: The columns :type fields: list :rtype: sql
def get_index_field_declaration_list_sql(self, fields): """ Obtains DBMS specific SQL code portion needed to set an index declaration to be used in statements like CREATE TABLE. :param fields: The columns :type fields: list :rtype: sql """ ret = [] ...
Returns the SQL to create an index on a table on this platform. :param index: The index :type index: Index :param table: The table :type table: Table or str :rtype: str
def get_create_index_sql(self, index, table): """ Returns the SQL to create an index on a table on this platform. :param index: The index :type index: Index :param table: The table :type table: Table or str :rtype: str """ if isinstance(table, T...
Returns the SQL to create an unnamed primary key constraint. :param index: The index :type index: Index :param table: The table :type table: Table or str :rtype: str
def get_create_primary_key_sql(self, index, table): """ Returns the SQL to create an unnamed primary key constraint. :param index: The index :type index: Index :param table: The table :type table: Table or str :rtype: str """ return "ALTER TABLE...
Returns the SQL to create a new foreign key. :rtype: sql
def get_create_foreign_key_sql(self, foreign_key, table): """ Returns the SQL to create a new foreign key. :rtype: sql """ if isinstance(table, Table): table = table.get_quoted_name(self) query = "ALTER TABLE %s ADD %s" % ( table, sel...
Returns the SQL snippet to drop an existing table. :param table: The table :type table: Table or str :rtype: str
def get_drop_table_sql(self, table): """ Returns the SQL snippet to drop an existing table. :param table: The table :type table: Table or str :rtype: str """ if isinstance(table, Table): table = table.get_quoted_name(self) return "DROP TABLE...
Returns the SQL to drop an index from a table. :param index: The index :type index: Index or str :param table: The table :type table: Table or str or None :rtype: str
def get_drop_index_sql(self, index, table=None): """ Returns the SQL to drop an index from a table. :param index: The index :type index: Index or str :param table: The table :type table: Table or str or None :rtype: str """ if isinstance(index, ...
Returns the SQL statement(s) to create a table with the specified name, columns and constraints on this platform. :param table: The table :type table: Table :type create_flags: int :rtype: str
def get_create_table_sql(self, table, create_flags=CREATE_INDEXES): """ Returns the SQL statement(s) to create a table with the specified name, columns and constraints on this platform. :param table: The table :type table: Table :type create_flags: int ...
Returns the SQL used to create a table. :param table_name: The name of the table to create :type table_name: str :param columns: The table columns :type columns: dict :param options: The options :type options: dict :rtype: str
def _get_create_table_sql(self, table_name, columns, options=None): """ Returns the SQL used to create a table. :param table_name: The name of the table to create :type table_name: str :param columns: The table columns :type columns: dict :param options: The op...
Quotes a string so that it can be safely used as a table or column name, even if it is a reserved word of the platform. This also detects identifier chains separated by dot and quotes them independently. :param string: The identifier name to be quoted. :type string: str :return...
def quote_identifier(self, string): """ Quotes a string so that it can be safely used as a table or column name, even if it is a reserved word of the platform. This also detects identifier chains separated by dot and quotes them independently. :param string: The identifier name ...
Quotes a single identifier (no dot chain separation). :param string: The identifier name to be quoted. :type string: str :return: The quoted identifier string. :rtype: str
def quote_single_identifier(self, string): """ Quotes a single identifier (no dot chain separation). :param string: The identifier name to be quoted. :type string: str :return: The quoted identifier string. :rtype: str """ c = self.get_identifier_quote_c...
Detects and sets the database platform. Evaluates custom platform class and version in order to set the correct platform. :raises InvalidPlatformSpecified: if an invalid platform was specified for this connection.
def _detect_database_platform(self): """ Detects and sets the database platform. Evaluates custom platform class and version in order to set the correct platform. :raises InvalidPlatformSpecified: if an invalid platform was specified for this connection. """ version = s...
Get the current page for the request. :param current_page: The current page of results :type current_page: int :rtype: int
def _set_current_page(self, current_page): """ Get the current page for the request. :param current_page: The current page of results :type current_page: int :rtype: int """ if not current_page: self.resolve_current_page() if not self._is_va...
Check for more pages. The last item will be sliced off.
def _check_for_more_pages(self): """ Check for more pages. The last item will be sliced off. """ self._has_more = len(self._items) > self.per_page self._items = self._items[0 : self.per_page]
Returns the difference between the tables table1 and table2. :type table1: Table :type table2: Table :rtype: TableDiff
def diff_table(self, table1, table2): """ Returns the difference between the tables table1 and table2. :type table1: Table :type table2: Table :rtype: TableDiff """ changes = 0 table_differences = TableDiff(table1.get_name()) table_differences.fr...
Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop however ambiguities between different possibilities should not lead to renaming at all. :type table_differences: TableDiff
def detect_index_renamings(self, table_differences): """ Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop however ambiguities between different possibilities should not lead to renaming at all. :type table_differences: Table...
:type key1: ForeignKeyConstraint :type key2: ForeignKeyConstraint :rtype: bool
def diff_foreign_key(self, key1, key2): """ :type key1: ForeignKeyConstraint :type key2: ForeignKeyConstraint :rtype: bool """ key1_unquoted_local_columns = [ c.lower() for c in key1.get_unquoted_local_columns() ] key2_unquoted_local_columns ...
Finds the difference between the indexes index1 and index2. Compares index1 with index2 and returns True if there are any differences or False in case there are no differences. :type index1: Index :type index2: Index :rtype: bool
def diff_index(self, index1, index2): """ Finds the difference between the indexes index1 and index2. Compares index1 with index2 and returns True if there are any differences or False in case there are no differences. :type index1: Index :type index2: Index :r...
Executes the command
def handle(self): """ Executes the command """ database = self.option("database") repository = DatabaseMigrationRepository(self.resolver, "migrations") repository.set_source(database) repository.create_repository() self.info("Migration table created succ...
Get the column listing for a given table. :param table: The table :type table: str :rtype: list
def get_column_listing(self, table): """ Get the column listing for a given table. :param table: The table :type table: str :rtype: list """ sql = self._grammar.compile_column_exists() database = self._connection.get_database_name() table = self....
Seed the given connection from the given class. :param klass: The Seeder class :type klass: class
def call(self, klass): """ Seed the given connection from the given class. :param klass: The Seeder class :type klass: class """ self._resolve(klass).run() if self._command: self._command.line("<info>Seeded:</info> <fg=cyan>%s</>" % klass.__name__)
Resolve an instance of the given seeder klass. :param klass: The Seeder class :type klass: class
def _resolve(self, klass): """ Resolve an instance of the given seeder klass. :param klass: The Seeder class :type klass: class """ resolver = None if self._resolver: resolver = self._resolver elif self._command: resolver = self._...
Set the columns to be selected :param columns: The columns to be selected :type columns: tuple :return: The current QueryBuilder instance :rtype: QueryBuilder
def select(self, *columns): """ Set the columns to be selected :param columns: The columns to be selected :type columns: tuple :return: The current QueryBuilder instance :rtype: QueryBuilder """ if not columns: columns = ["*"] self.c...
Add a new raw select expression to the query :param expression: The raw expression :type expression: str :param bindings: The expression bindings :type bindings: list :return: The current QueryBuilder instance :rtype: QueryBuilder
def select_raw(self, expression, bindings=None): """ Add a new raw select expression to the query :param expression: The raw expression :type expression: str :param bindings: The expression bindings :type bindings: list :return: The current QueryBuilder instanc...
Add a subselect expression to the query :param query: A QueryBuilder instance :type query: QueryBuilder :param as_: The subselect alias :type as_: str :return: The current QueryBuilder instance :rtype: QueryBuilder
def select_sub(self, query, as_): """ Add a subselect expression to the query :param query: A QueryBuilder instance :type query: QueryBuilder :param as_: The subselect alias :type as_: str :return: The current QueryBuilder instance :rtype: QueryBuilder ...
Add a new select column to query :param column: The column to add :type column: str :return: The current QueryBuilder instance :rtype: QueryBuilder
def add_select(self, *column): """ Add a new select column to query :param column: The column to add :type column: str :return: The current QueryBuilder instance :rtype: QueryBuilder """ if not column: column = [] self.columns += lis...
Add a "left join where" clause to the query :param table: The table to join with, can also be a JoinClause instance :type table: str or JoinClause :param one: The first column of the join condition :type one: str :param operator: The operator of the join condition :typ...
def left_join_where(self, table, one, operator, two): """ Add a "left join where" clause to the query :param table: The table to join with, can also be a JoinClause instance :type table: str or JoinClause :param one: The first column of the join condition :type one: str...
Add a right join to the query :param table: The table to join with, can also be a JoinClause instance :type table: str or JoinClause :param one: The first column of the join condition :type one: str :param operator: The operator of the join condition :type operator: st...
def right_join(self, table, one=None, operator=None, two=None): """ Add a right join to the query :param table: The table to join with, can also be a JoinClause instance :type table: str or JoinClause :param one: The first column of the join condition :type one: str ...
Add a "right join where" clause to the query :param table: The table to join with, can also be a JoinClause instance :type table: str or JoinClause :param one: The first column of the join condition :type one: str :param operator: The operator of the join condition :ty...
def right_join_where(self, table, one, operator, two): """ Add a "right join where" clause to the query :param table: The table to join with, can also be a JoinClause instance :type table: str or JoinClause :param one: The first column of the join condition :type one: s...
Add a where clause to the query :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str or QueryBuilder :param operator: The operator of the where clause :type operator: str :param value: The value of the where clause ...
def where(self, column, operator=Null(), value=None, boolean="and"): """ Add a where clause to the query :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str or QueryBuilder :param operator: The operator of the where...
Add a "group by" clause to the query :param columns: The columns to group by :type columns: tuple :return: The current QueryBuilder instance :rtype: QueryBuilder
def group_by(self, *columns): """ Add a "group by" clause to the query :param columns: The columns to group by :type columns: tuple :return: The current QueryBuilder instance :rtype: QueryBuilder """ for column in columns: self.groups.append(...
Add a "having" clause to the query :param column: The column :type column: str :param operator: The having clause operator :type operator: str :param value: The having clause value :type value: mixed :param boolean: Boolean joiner type :type boolean: s...
def having(self, column, operator=None, value=None, boolean="and"): """ Add a "having" clause to the query :param column: The column :type column: str :param operator: The having clause operator :type operator: str :param value: The having clause value ...
Add a raw having clause to the query :param sql: The raw query :type sql: str :param bindings: The query bindings :type bindings: list :param boolean: Boolean joiner type :type boolean: str :return: The current QueryBuilder instance :rtype: QueryBuilde...
def having_raw(self, sql, bindings=None, boolean="and"): """ Add a raw having clause to the query :param sql: The raw query :type sql: str :param bindings: The query bindings :type bindings: list :param boolean: Boolean joiner type :type boolean: str ...
Add a "order by" clause to the query :param column: The order by column :type column: str :param direction: The direction of the order :type direction: str :return: The current QueryBuilder instance :rtype: QueryBuilder
def order_by(self, column, direction="asc"): """ Add a "order by" clause to the query :param column: The order by column :type column: str :param direction: The direction of the order :type direction: str :return: The current QueryBuilder instance :rtyp...
Add a raw "order by" clause to the query :param sql: The raw clause :type sql: str :param bindings: The bdings :param bindings: list :return: The current QueryBuilder instance :rtype: QueryBuilder
def order_by_raw(self, sql, bindings=None): """ Add a raw "order by" clause to the query :param sql: The raw clause :type sql: str :param bindings: The bdings :param bindings: list :return: The current QueryBuilder instance :rtype: QueryBuilder ...
Execute the query and get the first results :param limit: The number of results to get :type limit: int :param columns: The columns to get :type columns: list :return: The result :rtype: mixed
def first(self, limit=1, columns=None): """ Execute the query and get the first results :param limit: The number of results to get :type limit: int :param columns: The columns to get :type columns: list :return: The result :rtype: mixed """ ...
Execute the query as a "select" statement :param columns: The columns to get :type columns: list :return: The result :rtype: Collection
def get(self, columns=None): """ Execute the query as a "select" statement :param columns: The columns to get :type columns: list :return: The result :rtype: Collection """ if not columns: columns = ["*"] original = self.columns ...
Run the query as a "select" statement against the connection. :return: The result :rtype: list
def _run_select(self): """ Run the query as a "select" statement against the connection. :return: The result :rtype: list """ return self._connection.select( self.to_sql(), self.get_bindings(), not self._use_write_connection )
Paginate the given query. :param per_page: The number of records per page :type per_page: int :param current_page: The current page of results :type current_page: int :param columns: The columns to return :type columns: list :return: The paginator :rty...
def paginate(self, per_page=15, current_page=None, columns=None): """ Paginate the given query. :param per_page: The number of records per page :type per_page: int :param current_page: The current page of results :type current_page: int :param columns: The colu...
Paginate the given query. :param per_page: The number of records per page :type per_page: int :param current_page: The current page of results :type current_page: int :param columns: The columns to return :type columns: list :return: The paginator :rty...
def simple_paginate(self, per_page=15, current_page=None, columns=None): """ Paginate the given query. :param per_page: The number of records per page :type per_page: int :param current_page: The current page of results :type current_page: int :param columns: T...
Chunk the results of the query :param count: The chunk size :type count: int :return: The current chunk :rtype: list
def chunk(self, count): """ Chunk the results of the query :param count: The chunk size :type count: int :return: The current chunk :rtype: list """ for chunk in self._connection.select_many( count, self.to_sql(), self.get_bindings(), not sel...