Search is not available for this dataset
text
stringlengths
75
104k
def get_last(self): """ Get the last migration batch. :rtype: list """ query = self.table().where('batch', self.get_last_batch_number()) return query.order_by('migration', 'desc').get()
def compile_insert(self, query, values): """ Compile an insert SQL statement :param query: A QueryBuilder instance :type query: QueryBuilder :param values: The values to insert :type values: dict or list :return: The compiled statement :rtype: str ...
def get_alter_table_sql(self, diff): """ Get the ALTER TABLE SQL statement :param diff: The table diff :type diff: eloquent.dbal.table_diff.TableDiff :rtype: list """ sql = [] for column_diff in diff.changed_columns.values(): if self.is_unch...
def _date_based_where(self, type, query, where): """ Compiled a date where based clause :param type: The date type :type type: str :param query: A QueryBuilder instance :type query: QueryBuilder :param where: The condition :type where: dict :re...
def compile_select(self, query): """ Compile a select query into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :return: The compiled sql :rtype: str """ sql = super(MySqlQueryGrammar, self).compile_select(query) if query.un...
def _compile_lock(self, query, value): """ Compile the lock into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :param value: The lock value :type value: bool or str :return: The compiled lock :rtype: str """ if isin...
def compile_update(self, query, values): """ Compile an update statement into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :param values: The update values :type values: dict :return: The compiled update :rtype: str """ ...
def collapse(self): """ Collapse the collection items into a single element (dict or list) :return: A new Collection instance with collapsed items :rtype: Collection """ results = [] if isinstance(self._items, dict): items = self._items.values() ...
def contains(self, key, value=None): """ Determine if an element is in the collection :param key: The element :type key: int or str :param value: The value of the element :type value: mixed :return: Whether the element is in the collection :rtype: bool ...
def lists(self, value, key=None): """ Get a list with the values of a given key :rtype: list """ results = map(lambda x: x[value], self._items) return list(results)
def map(self, callback): """ Run a map over each of the item. :param callback: The map function :type callback: callable :rtype: Collection """ if isinstance(self._items, dict): return Collection(list(map(callback, self._items.values()))) re...
def unique(self): """ Return only unique items from the collection list. :rtype: Collection """ seen = set() seen_add = seen.add return Collection([x for x in self._items if not (x in seen or seen_add(x))])
def load(self, *relations): """ Load a set of relationships onto the collection. """ if len(self._items) > 0: query = self.first().new_query().with_(*relations) self._items = query.eager_load_relations(self._items) return self
def compile_foreign(self, blueprint, command, _): """ Compile a foreign key command. :param blueprint: The blueprint :type blueprint: Blueprint :param command: The command :type command: Fluent :rtype: str """ table = self.wrap_table(blueprint) ...
def _get_columns(self, blueprint): """ Get the blueprint's columns definitions. :param blueprint: The blueprint :type blueprint: Blueprint :rtype: list """ columns = [] for column in blueprint.get_added_columns(): sql = self.wrap(column) + '...
def _add_modifiers(self, sql, blueprint, column): """ Add the column modifiers to the deifinition """ for modifier in self._modifiers: method = '_modify_%s' % modifier if hasattr(self, method): sql += getattr(self, method)(blueprint, column) ...
def _clean_pivot_attributes(self, model): """ Get the pivot attributes from a model. :type model: eloquent.Model """ values = {} delete_keys = [] for key, value in model.get_attributes().items(): if key.find('pivot_') == 0: values[key...
def get_relation_count_query_for_self_join(self, query, parent): """ Add the constraints for a relationship count query on the same table. :type query: eloquent.orm.Builder :type parent: eloquent.orm.Builder :rtype: eloquent.orm.Builder """ query.select(QueryExp...
def _get_select_columns(self, columns=None): """ Set the select clause for the relation query. :param columns: The columns :type columns: list :rtype: list """ if columns == ['*'] or columns is None: columns = ['%s.*' % self._related.get_table()] ...
def _get_aliased_pivot_columns(self): """ Get the pivot columns for the relation. :rtype: list """ defaults = [self._foreign_key, self._other_key] columns = [] for column in defaults + self._pivot_columns: value = '%s.%s AS pivot_%s' % (self._table,...
def _set_join(self, query=None): """ Set the join clause for the relation query. :param query: The query builder :type query: eloquent.orm.Builder :return: self :rtype: BelongsToMany """ if not query: query = self._query base_table =...
def match(self, models, results, relation): """ Match the eagerly loaded results to their parents. :type models: list :type results: Collection :type relation: str """ dictionary = self._build_dictionary(results) for model in models: key = m...
def save(self, model, joining=None, touch=True): """ Save a new model and attach it to the parent model. :type model: eloquent.Model :type joining: dict :type touch: bool :rtype: eloquent.Model """ if joining is None: joining = {} mo...
def _attach_new(self, records, current, touch=True): """ Attach all of the IDs that aren't in the current dict. """ changes = { 'attached': [], 'updated': [] } for id, attributes in records.items(): if id not in current: ...
def update_existing_pivot(self, id, attributes, touch=True): """ Update an existing pivot record on the table. """ if self.updated_at() in self._pivot_columns: attributes = self.set_timestamps_on_attach(attributes, True) updated = self._new_picot_statement_for_id(id)...
def query(self): """ Begin a fluent query :return: A QueryBuilder instance :rtype: QueryBuilder """ query = QueryBuilder(self, self._query_grammar, self._post_processor) return query
def force_delete(self): """ Force a hard delete on a soft deleted model. """ self._force_deleting = True self.delete() self._force_deleting = False
def _do_perform_delete_on_model(self): """ Perform the actual delete query on this model instance. """ if self._force_deleting: return self.with_trashed().where(self.get_key_name(), self.get_key()).force_delete() return self._run_soft_delete()
def restore(self): """ Restore a soft-deleted model instance. """ setattr(self, self.get_deleted_at_column(), None) self.set_exists(True) result = self.save() return result
def join(self, table, one=None, operator=None, two=None, type='inner', where=False): """ Add a join 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 c...
def join_where(self, table, one, operator, two, type='inner'): """ Add a "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:...
def _where_in_sub(self, column, query, boolean, negate=False): """ Add a where in with a sub select to the query :param column: The column :type column: str :param query: A QueryBuilder instance :type query: QueryBuilder :param boolean: The boolean operator ...
def or_having(self, column, operator=None, value=None): """ 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:...
def union(self, query, all=False): """ Add a union statement to the query :param query: A QueryBuilder instance :type query: QueryBuilder :param all: Whether it is a "union all" statement :type all: bool :return: The query :rtype: QueryBuilder "...
def find(self, id, columns=None): """ Execute a query for a single record by id :param id: The id of the record to retrieve :type id: mixed :param columns: The columns of the record to retrive :type columns: list :return: mixed :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 """ ...
def get_fresh(self, columns=None): """ Execute the query as a fresh "select" statement :param columns: The columns to get :type columns: list :return: The result :rtype: list """ if not columns: columns = ['*'] if not self.columns: ...
def _get_list_select(self, column, key=None): """ Get the columns that should be used in a list :param column: The column to get the values for :type column: str :param key: The key :type key: str :return: The list of values :rtype: list """ ...
def increment(self, column, amount=1, extras=None): """ Increment a column's value by a given amount :param column: The column to increment :type column: str :param amount: The amount by which to increment :type amount: int :param extras: Extra columns ...
def delete(self, id=None): """ Delete a record from the database :param id: The id of the row to delete :type id: mixed :return: The number of rows deleted :rtype: int """ if id is not None: self.where('id', '=', id) sql = self._gram...
def merge_wheres(self, wheres, bindings): """ Merge a list of where clauses and bindings :param wheres: A list of where clauses :type wheres: list :param bindings: A list of bindings :type bindings: list :rtype: None """ self.wheres = self.where...
def execute(self, i, o): """ Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output """ super(MigrateMakeCommand, self).execute(i, o) creator = MigrationCreator() name = i.get_argument('name') table = i.get_op...
def remove(self, builder, model): """ Remove the scope from a given query builder. :param builder: The query builder :type builder: eloquent.orm.builder.Builder :param model: The model :type model: eloquent.orm.Model """ column = model.get_qualified_dele...
def extend(self, builder): """ Extend the query builder with the needed functions. :param builder: The query builder :type builder: eloquent.orm.builder.Builder """ for extension in self._extensions: getattr(self, '_add_%s' % extension)(builder) buil...
def _only_trashed(self, builder): """ The only-trashed extension. :param builder: The query builder :type builder: eloquent.orm.builder.Builder """ model = builder.get_model() self.remove(builder, model) builder.get_query().where_not_null(model.get_qual...
def _add_fluent_indexes(self): """ Add the index commands fluently specified on columns: """ for column in self._columns: for index in ['primary', 'unique', 'index']: column_index = column.get(index) if column_index is True: ...
def big_integer(self, column, auto_increment=False, unsigned=False): """ Create a new big integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent """ return self._a...
def medium_integer(self, column, auto_increment=False, unsigned=False): """ Create a new medium integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent """ return s...
def tiny_integer(self, column, auto_increment=False, unsigned=False): """ Create a new tiny integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent """ return self....
def _add_column(self, type, name, **parameters): """ Add a new column to the blueprint. :param type: The column type :type type: str :param name: The column name :type name: str :param parameters: The column parameters :type parameters: dict :r...
def get_alter_table_sql(self, diff): """ Get the ALTER TABLE SQL statement :param diff: The table diff :type diff: eloquent.dbal.table_diff.TableDiff :rtype: list """ #sql = self._get_simple_alter_table_sql(diff) from_table = diff.from_table if ...
def get_foreign_keys_in_altered_table(self, diff): """ :param diff: The table diff :type diff: eloquent.dbal.table_diff.TableDiff :rtype: list """ foreign_keys = diff.from_table.get_foreign_keys() column_names = self.get_column_names_in_altered_table(diff) ...
def get_relation_count_query(self, query, parent): """ Add the constraints for a relationship count query. :type query: eloquent.orm.Builder :type parent: eloquent.orm.Builder :rtype: Builder """ query.select(QueryExpression('COUNT(*)')) other_key = sel...
def match(self, models, results, relation): """ Match the eagerly loaded results to their parents. :type models: list :type results: Collection :type relation: str """ foreign = self._foreign_key other = self._other_key dictionary = {} ...
def associate(self, model): """ Associate the model instance to the given parent. :type model: eloquent.Model :rtype: eloquent.Model """ self._parent.set_attribute(self._foreign_key, model.get_attribute(self._other_key)) return self._parent.set_relation(self._r...
def dissociate(self): """ Dissociate previously associated model from the given parent. :rtype: eloquent.Model """ self._parent.set_attribute(self._foreign_key, None) return self._parent.set_relation(self._relation, None)
def execute(self, i, o): """ Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output """ super(StatusCommand, self).execute(i, o) database = i.get_option('database') repository = DatabaseMigrationRepository(self._resolv...
def compile_rename_column(self, blueprint, command, connection): """ Compile a rename column command. :param blueprint: The blueprint :type blueprint: Blueprint :param command: The command :type command: Fluent :param connection: The connection :type co...
def compile_change(self, blueprint, command, connection): """ Compile a change column command into a series of SQL statement. :param blueprint: The blueprint :type blueprint: eloquent.schema.Blueprint :param command: The command :type command: Fluent :param con...
def compile_create(self, blueprint, command, _): """ Compile a create table command. """ columns = ', '.join(self._get_columns(blueprint)) sql = 'CREATE TABLE %s (%s' % (self.wrap_table(blueprint), columns) sql += self._add_foreign_keys(blueprint) sql += self._...
def match_one(self, models, results, relation): """ 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 :t...
def match_many(self, models, results, relation): """ 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 :...
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 rela...
def _get_relation_value(self, dictionary, key, type): """ Get the value of the relationship by one or many type. :type dictionary: dict :type key: str :type type: str """ value = dictionary[key] if type == 'one': return value[0] retu...
def first_or_new(self, _attributes=None, **attributes): """ Get the first related model record matching the attributes or instantiate it. :param attributes: The attributes :type attributes: dict :rtype: Model """ if _attributes is not None: attribut...
def first_or_create(self, _attributes=None, **attributes): """ Get the first related record matching the attributes or create it. :param attributes: The attributes :type attributes: dict :rtype: Model """ if _attributes is not None: attributes.updat...
def execute(self, i, o): """ Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output """ super(ResetCommand, self).execute(i, o) dialog = self.get_helper('dialog') confirm = dialog.ask_confirmation( o, ...
def get_relation_count_query(self, query, parent): """ Add the constraints for a relationship count query. :type query: eloquent.orm.Builder :type parent: eloquent.orm.Builder :rtype: eloquent.orm.Builder """ query = super(MorphToMany, self).get_relation_count_q...
def add_eager_constraints(self, models): """ Set the constraints for an eager load of the relation. :type models: list """ super(MorphToMany, self).add_eager_constraints(models) self._query.where('%s.%s' % (self._table, self._morph_type), self._morph_class)
def _create_attach_record(self, id, timed): """ Create a new pivot attachement record. """ record = super(MorphToMany, self)._create_attach_record(id, timed) record[self._morph_type] = self._morph_class return record
def _new_pivot_query(self): """ Create a new query builder for the pivot table. :rtype: eloquent.orm.Builder """ query = super(MorphToMany, self)._new_pivot_query() return query.where(self._morph_type, self._morph_class)
def new_pivot(self, attributes=None, exists=False): """ Create a new pivot model instance. """ from .morph_pivot import MorphPivot pivot = MorphPivot(self._parent, attributes, self._table, exists) pivot.set_pivot_keys(self._foreign_key, self._other_key)\ .se...
def execute(self, i, o): """ Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output """ super(InstallCommand, self).execute(i, o) database = i.get_option('database') repository = DatabaseMigrationRepository(self._resol...
def process_insert_get_id(self, query, sql, values, sequence=None): """ Process an "insert get ID" query. :param query: A QueryBuilder instance :type query: QueryBuilder :param sql: The sql query to execute :type sql: str :param values: The value bindings ...
def chunk(self, count): """ Chunk the results of the query :param count: The chunk size :type count: int :return: The current chunk :rtype: list """ page = 1 results = self.for_page(page, count).get() while results: yield res...
def lists(self, column, key=None): """ Get a list with the values of a given column :param column: The column to get the values for :type column: str :param key: The key :type key: str :return: The list of values :rtype: list or dict """ ...
def increment(self, column, amount=1, extras=None): """ Increment a column's value by a given amount :param column: The column to increment :type column: str :param amount: The amount by which to increment :type amount: int :param extras: Extra columns ...
def decrement(self, column, amount=1, extras=None): """ Decrement a column's value by a given amount :param column: The column to increment :type column: str :param amount: The amount by which to increment :type amount: int :param extras: Extra columns ...
def get_models(self, columns=None): """ Get the hydrated models without eager loading. :param columns: The columns to get :type columns: list :return: A list of models :rtype: list """ results = self._query.get(columns) connection = self._model....
def eager_load_relations(self, models): """ Eager load the relationship of the models. :param models: :type models: list :return: The models :rtype: list """ for name, constraints in self._eager_load.items(): if name.find('.') == -1: ...
def _load_relation(self, models, name, constraints): """ Eagerly load the relationship on a set of models. :rtype: list """ relation = self.get_relation(name) relation.add_eager_constraints(models) if callable(constraints): constraints(relation) ...
def _has_nested(self, relations, operator='>=', count=1, boolean='and', extra=None): """ Add nested relationship count conditions to the query. :param relations: nested relations :type relations: str :param operator: The operator :type operator: str :param coun...
def doesnt_have(self, relation, boolean='and', extra=None): """ Add a relationship count to the query. :param relation: The relation to count :type relation: str :param boolean: The boolean value :type boolean: str :param extra: The extra query :type ex...
def where_has(self, relation, extra, operator='>=', count=1): """ Add a relationship count condition to the query with where clauses. :param relation: The relation to count :type relation: str :param extra: The extra query :type extra: Builder or callable :para...
def or_has(self, relation, operator='>=', count=1): """ Add a relationship count condition to the query with an "or". :param relation: The relation to count :type relation: str :param operator: The operator :type operator: str :param count: The count :t...
def or_where_has(self, relation, extra, operator='>=', count=1): """ Add a relationship count condition to the query with where clauses and an "or". :param relation: The relation to count :type relation: str :param extra: The extra query :type extra: Builder or callable...
def _merge_wheres_to_has(self, has_query, relation): """ Merge the "wheres" from the relation query to a has query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: eloquent.orm.relations.Relation ""...
def _get_has_relation_query(self, relation): """ Get the "has" relation base query :type relation: str :rtype: Builder """ from .relations import Relation return Relation.no_constraints( lambda: getattr(self.get_model(), relation)() )
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_relations(list(relations)) self._eager_load.upda...
def _parse_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): ...
def _parse_nested(self, name, results): """ Parse the nested relationship in a relation. :param name: The name of the relationship :type name: str :type results: dict :rtype: dict """ progress = [] for segment in name.split('.'): pr...
def _call_scope(self, scope, *args, **kwargs): """ Call the given model scope. :param scope: The scope to call :type scope: str """ result = getattr(self._model, scope)(self, *args, **kwargs) return result or self
def _run_up(self, path, migration_file, batch, pretend=False): """ Run "up" a migration instance. :type migration_file: str :type batch: int :type pretend: bool """ migration = self._resolve(path, migration_file) if pretend: return self._pr...
def rollback(self, path, pretend=False): """ Rollback the last migration operation. :param path: The path :type path: str :param pretend: Whether we execute the migrations as dry-run :type pretend: bool :rtype: int """ self._notes = [] ...
def _run_down(self, path, migration, pretend=False): """ Run "down" a migration instance. """ migration_file = migration['migration'] instance = self._resolve(path, migration_file) if pretend: return self._pretend_to_run(instance, 'down') instance.d...
def _pretend_to_run(self, migration, method): """ Pretend to run the migration. :param migration: The migration :type migration: eloquent.migrations.migration.Migration :param method: The method to execute :type method: str """ for query in self._get_que...
def _get_queries(self, migration, method): """ Get all of the queries that would be run for a migration. :param migration: The migration :type migration: eloquent.migrations.migration.Migration :param method: The method to execute :type method: str :rtype: list...
def _resolve(self, path, migration_file): """ Resolve a migration instance from a file. :param migration_file: The migration file :type migration_file: str :rtype: eloquent.migrations.migration.Migration """ variables = {} name = '_'.join(migration_file...
def get_alter_table_sql(self, diff): """ Get the ALTER TABLE SQL statement :param diff: The table diff :type diff: eloquent.dbal.table_diff.TableDiff :rtype: list """ column_sql = [] query_parts = [] if diff.new_name is not False: qu...
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...