text
stringlengths
81
112k
Save a new model and attach it to the parent model. :type model: eloquent.Model :type joining: dict :type touch: bool :rtype: eloquent.Model def save(self, model, joining=None, touch=True): """ Save a new model and attach it to the parent model. :type model: e...
Attach all of the IDs that aren't in the current dict. 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.i...
Update an existing pivot record on the table. 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) ...
Begin a fluent query :return: A QueryBuilder instance :rtype: QueryBuilder def query(self): """ Begin a fluent query :return: A QueryBuilder instance :rtype: QueryBuilder """ query = QueryBuilder(self, self._query_grammar, self._post_processor) ...
Force a hard delete on a soft deleted model. def force_delete(self): """ Force a hard delete on a soft deleted model. """ self._force_deleting = True self.delete() self._force_deleting = False
Perform the actual delete query on this model instance. 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() ...
Restore a soft-deleted model instance. 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
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 condition :type one: str :param operator: The operator of the join condition :type operator: s...
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: str :param operator: The operator of the join condition :type ope...
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 :type boolean: str :param negate: Whether it is a not where in ...
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 :return: The current QueryBuilder instance :rtype: Q...
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 union(self, query, all=False): """ Add a un...
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 find(self, id, columns=None): """ Execute a ...
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 que...
Execute the query as a fresh "select" statement :param columns: The columns to get :type columns: list :return: The result :rtype: list def get_fresh(self, columns=None): """ Execute the query as a fresh "select" statement :param columns: The columns to get ...
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 _get_list_select(self, column, key=None): """ Get the column...
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 :type extras: dict :return: The number of rows affected ...
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 def delete(self, id=None): """ Delete a record from the database :param id: The id of the row to delete :type id: m...
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 def merge_wheres(self, wheres, bindings): """ Merge a list of where clauses and bindings ...
Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output def execute(self, i, o): """ Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output """ super(MigrateMakeCommand, self).execut...
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 def remove(self, builder, model): """ Remove the scope from a given query builder. ...
Extend the query builder with the needed functions. :param builder: The query builder :type builder: eloquent.orm.builder.Builder def extend(self, builder): """ Extend the query builder with the needed functions. :param builder: The query builder :type builder: eloquen...
The only-trashed extension. :param builder: The query builder :type builder: eloquent.orm.builder.Builder def _only_trashed(self, builder): """ The only-trashed extension. :param builder: The query builder :type builder: eloquent.orm.builder.Builder """ ...
Add the index commands fluently specified on columns: 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) ...
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 def big_integer(self, column, auto_increment=False, unsigned=False): """ Create a new big integer column o...
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 def medium_integer(self, column, auto_increment=False, unsigned=False): """ Create a new medium integer...
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 def tiny_integer(self, column, auto_increment=False, unsigned=False): """ Create a new tiny integer colum...
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 :rtype: Fluent def _add_column(self, type, name, **parameters): ...
Get the ALTER TABLE SQL statement :param diff: The table diff :type diff: eloquent.dbal.table_diff.TableDiff :rtype: list def get_alter_table_sql(self, diff): """ Get the ALTER TABLE SQL statement :param diff: The table diff :type diff: eloquent.dbal.table_dif...
:param diff: The table diff :type diff: eloquent.dbal.table_diff.TableDiff :rtype: list 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 = dif...
Add the constraints for a relationship count query. :type query: eloquent.orm.Builder :type parent: eloquent.orm.Builder :rtype: Builder def get_relation_count_query(self, query, parent): """ Add the constraints for a relationship count query. :type query: eloquent.or...
Match the eagerly loaded results to their parents. :type models: list :type results: Collection :type relation: str def match(self, models, results, relation): """ Match the eagerly loaded results to their parents. :type models: list :type results: Collection ...
Associate the model instance to the given parent. :type model: eloquent.Model :rtype: eloquent.Model def associate(self, model): """ Associate the model instance to the given parent. :type model: eloquent.Model :rtype: eloquent.Model """ self._parent....
Dissociate previously associated model from the given parent. :rtype: eloquent.Model def dissociate(self): """ Dissociate previously associated model from the given parent. :rtype: eloquent.Model """ self._parent.set_attribute(self._foreign_key, None) return s...
Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output 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, ...
Compile a rename column command. :param blueprint: The blueprint :type blueprint: Blueprint :param command: The command :type command: Fluent :param connection: The connection :type connection: eloquent.connections.Connection :rtype: list def compile_rename_c...
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 connection: The connection :type connection: eloquent.connections.Connect...
Compile a create table command. 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(...
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 :rtype: list def match_one(self, models,...
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 :rtype: list def match_many(self, models...
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 :type...
Get the value of the relationship by one or many type. :type dictionary: dict :type key: str :type type: str 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 ...
Get the first related model record matching the attributes or instantiate it. :param attributes: The attributes :type attributes: dict :rtype: Model def first_or_new(self, _attributes=None, **attributes): """ Get the first related model record matching the attributes or insta...
Get the first related record matching the attributes or create it. :param attributes: The attributes :type attributes: dict :rtype: Model def first_or_create(self, _attributes=None, **attributes): """ Get the first related record matching the attributes or create it. ...
Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output 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...
Add the constraints for a relationship count query. :type query: eloquent.orm.Builder :type parent: eloquent.orm.Builder :rtype: eloquent.orm.Builder def get_relation_count_query(self, query, parent): """ Add the constraints for a relationship count query. :type query...
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 """ super(MorphToMany, self).add_eager_constraints(models) self._qu...
Create a new pivot attachement record. 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
Create a new query builder for the pivot table. :rtype: eloquent.orm.Builder 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...
Create a new pivot model instance. 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_ke...
Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output 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,...
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 :type values: list :param sequence: The ids sequence :type sequence:...
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 ...
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 lists(self, column, key=None): """ Get a list with th...
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 :type extras: dict :return: The number of rows affected ...
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 :type extras: dict :return: The number of rows affected ...
Get the hydrated models without eager loading. :param columns: The columns to get :type columns: list :return: A list of models :rtype: list def get_models(self, columns=None): """ Get the hydrated models without eager loading. :param columns: The columns to g...
Eager load the relationship of the models. :param models: :type models: list :return: The models :rtype: list def eager_load_relations(self, models): """ Eager load the relationship of the models. :param models: :type models: list :return: The...
Eagerly load the relationship on a set of models. :rtype: list 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)...
Add nested relationship count conditions to the query. :param relations: nested relations :type relations: str :param operator: The operator :type operator: str :param count: The count :type count: int :param boolean: The boolean value :type boolean: s...
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 extra: Builder or callable :rtype: Builder def doesnt_have(self, relatio...
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 :param operator: The operator :type operator: str :param count: The co...
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 :type count: int :rtype: Builder def or_has(self, relation, oper...
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 :param operator: The operator :type operator: str :param c...
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 _merge_wheres_to_has(self, has_query, relation): """ Merge the...
Get the "has" relation base query :type relation: str :rtype: Builder def _get_has_relation_query(self, relation): """ Get the "has" relation base query :type relation: str :rtype: Builder """ from .relations import Relation return Relation.n...
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...
Parse a list of relations into individuals. :param relations: The relation to parse :type relations: list :rtype: dict def _parse_relations(self, relations): """ Parse a list of relations into individuals. :param relations: The relation to parse :type relation...
Parse the nested relationship in a relation. :param name: The name of the relationship :type name: str :type results: dict :rtype: dict def _parse_nested(self, name, results): """ Parse the nested relationship in a relation. :param name: The name of the relat...
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 """ result = getattr(self._model, scope)(self, *...
Run "up" a migration instance. :type migration_file: str :type batch: int :type pretend: bool def _run_up(self, path, migration_file, batch, pretend=False): """ Run "up" a migration instance. :type migration_file: str :type batch: int :type pretend:...
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 def rollback(self, path, pretend=False): """ Rollback the last migration operation. ...
Run "down" a migration instance. 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(ins...
Pretend to run the migration. :param migration: The migration :type migration: eloquent.migrations.migration.Migration :param method: The method to execute :type method: str def _pretend_to_run(self, migration, method): """ Pretend to run the migration. :param...
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 _get_queries(self, migration, method): """ ...
Resolve a migration instance from a file. :param migration_file: The migration file :type migration_file: str :rtype: eloquent.migrations.migration.Migration def _resolve(self, path, migration_file): """ Resolve a migration instance from a file. :param migration_file:...
Get the ALTER TABLE SQL statement :param diff: The table diff :type diff: eloquent.dbal.table_diff.TableDiff :rtype: list def get_alter_table_sql(self, diff): """ Get the ALTER TABLE SQL statement :param diff: The table diff :type diff: eloquent.dbal.table_dif...
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: Tabl...
Try to find columns that only changed their names. :type table_differences: TableDiff def detect_column_renamings(self, table_differences): """ Try to find columns that only changed their names. :type table_differences: TableDiff """ rename_candidates = {} for...
Returns the difference between column1 and column2 :type column1: eloquent.dbal.column.Column :type column2: eloquent.dbal.column.Column :rtype: list def diff_column(self, column1, column2): """ Returns the difference between column1 and column2 :type column1: eloquen...
Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output def execute(self, i, o): """ Executes the command. :type i: cleo.inputs.input.Input :type o: cleo.outputs.output.Output """ config = self._get_config(i) s...
Call another command. :param name: The command name :type name: str :param options: The options :type options: list or None :param o: The output :type o: cleo.outputs.output.Output def call(self, name, options=None, o=None): """ Call another command. ...
Get the config. :type i: cleo.inputs.input.Input :rtype: dict def _get_config(self, i): """ Get the config. :type i: cleo.inputs.input.Input :rtype: dict """ variables = {} if not i.get_option('config'): raise Exception('The --conf...
Associate the model instance to the given parent. :type model: eloquent.Model :rtype: eloquent.Model def associate(self, model): """ Associate the model instance to the given parent. :type model: eloquent.Model :rtype: eloquent.Model """ self._parent....
Create a new model instance by type. :rtype: Model def _create_model_by_type(self, type): """ Create a new model instance by type. :rtype: Model """ klass = None for cls in eloquent.orm.model.Model.__subclasses__(): morph_class = cls.__morph_class__...
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 """ ...
Populate the placeholders in the migration stub. :param name: The name of the migration :type name: str :param stub: The stub :type stub: str :param table: The table name :type table: str :rtype: str def _populate_stub(self, name, stub, table): """ ...
Set the keys for a save update query. :param query: A Builder instance :type query: eloquent.orm.Builder :return: The Builder instance :rtype: eloquent.orm.Builder def _set_keys_for_save_query(self, query): """ Set the keys for a save update query. :param quer...
Delete the pivot model record from the database. :rtype: int def delete(self): """ Delete the pivot model record from the database. :rtype: int """ query = self._get_delete_query() query.where(self._morph_type, self._morph_class) return query.delete()
Add the constraints for a relationship count query. :type query: Builder :type parent: Builder :rtype: Builder def get_relation_count_query(self, query, parent): """ Add the constraints for a relationship count query. :type query: Builder :type parent: Builder...
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 """ super(MorphOneOrMany, self).add_eager_constraints(models) self....
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 ...
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...
Set the foreign ID and type for creation a related model. def _set_foreign_attributes_for_create(self, model): """ Set the foreign ID and type for creation a related model. """ model.set_attribute(self.get_plain_foreign_key(), self.get_parent_key()) model.set_attribute(self.get...
Parse the connection into a tuple of the name and read / write type :param name: The name of the connection :type name: str :return: A tuple of the name and read / write type :rtype: tuple def _parse_connection_name(self, name): """ Parse the connection into a tuple of...
Disconnect from the given database and remove from local cache :param name: The name of the connection :type name: str :rtype: None def purge(self, name=None): """ Disconnect from the given database and remove from local cache :param name: The name of the connection ...
Runs a callback with constraints disabled on the relation. def no_constraints(cls, callback): """ Runs a callback with constraints disabled on the relation. """ cls._constraints = False results = callback() cls._constraints = True return results
Get all the primary keys for an array of models. :type models: list :type key: str :rtype: list def get_keys(self, models, key=None): """ Get all the primary keys for an array of models. :type models: list :type key: str :rtype: list """ ...
Set the base constraints on the relation query. :rtype: None def add_constraints(self): """ Set the base constraints on the relation query. :rtype: None """ parent_table = self._parent.get_table() self._set_join() if self._constraints: sel...
Add the constraints for a relationship count query. :type query: Builder :type parent: Builder :rtype: Builder def get_relation_count_query(self, query, parent): """ Add the constraints for a relationship count query. :type query: Builder :type parent: Builder...