INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Get the query builder for a delete operation on the pivot. :rtype: orator.orm.Builder
def _get_delete_query(self): """ Get the query builder for a delete operation on the pivot. :rtype: orator.orm.Builder """ foreign = self.get_attribute(self.__foreign_key) query = self.new_query().where(self.__foreign_key, foreign) return query.where(self.__oth...
Set the key names for the pivot model instance
def set_pivot_keys(self, foreign_key, other_key): """ Set the key names for the pivot model instance """ self.__foreign_key = foreign_key self.__other_key = other_key return self
Create a collection of models and persist them to the database. :param attributes: The models attributes :type attributes: dict :return: mixed
def create(self, **attributes): """ Create a collection of models and persist them to the database. :param attributes: The models attributes :type attributes: dict :return: mixed """ results = self.make(**attributes) if self._amount == 1: if...
Create a collection of models. :param attributes: The models attributes :type attributes: dict :return: mixed
def make(self, **attributes): """ Create a collection of models. :param attributes: The models attributes :type attributes: dict :return: mixed """ if self._amount == 1: return self._make_instance(**attributes) else: results = [] ...
Make an instance of the model with the given attributes. :param attributes: The models attributes :type attributes: dict :return: mixed
def _make_instance(self, **attributes): """ Make an instance of the model with the given attributes. :param attributes: The models attributes :type attributes: dict :return: mixed """ definition = self._definitions[self._klass][self._name](self._faker) d...
Special decorator encapsulating query method.
def run(wrapped): """ Special decorator encapsulating query method. """ @wraps(wrapped) def _run(self, query, bindings=None, *args, **kwargs): self._reconnect_if_missing_connection() start = time.time() try: result = wrapped(self, query, bindings, *args, **kwarg...
Set a where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of the where clause :type operator: str :param value: The value of the where cl...
def where_pivot(self, column, operator=None, value=None, boolean="and"): """ Set a where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of ...
Begin a fluent query :return: A QueryBuilder instance :rtype: QueryBuilder
def query(self): """ Begin a fluent query :return: A QueryBuilder instance :rtype: QueryBuilder """ query = self._builder_class( self, self._query_grammar, self._post_processor, **self._builder_default_kwargs ) ...
Set an or where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of the where clause :type operator: str :param value: The value of the wher...
def or_where_pivot(self, column, operator=None, value=None): """ Set an or where clause for a pivot table column. :param column: The column of the where clause, can also be a QueryBuilder instance for sub where :type column: str|Builder :param operator: The operator of the wher...
Execute the query and get the first result. :type columns: list
def first(self, columns=None): """ Execute the query and get the first result. :type columns: list """ self._query.take(1) results = self.get(columns) if len(results) > 0: return results.first() return
Execute the query and get the first result or raise an exception. :type columns: list :raises: ModelNotFound
def first_or_fail(self, columns=None): """ Execute the query and get the first result or raise an exception. :type columns: list :raises: ModelNotFound """ model = self.first(columns) if model is not None: return model raise ModelNotFound(se...
Execute the query as a "select" statement. :type columns: list :rtype: orator.Collection
def get(self, columns=None): """ Execute the query as a "select" statement. :type columns: list :rtype: orator.Collection """ if columns is None: columns = ["*"] if self._query.get_query().columns: columns = [] select = self._ge...
Hydrate the pivot table relationship on the models. :type models: list
def _hydrate_pivot_relation(self, models): """ Hydrate the pivot table relationship on the models. :type models: list """ for model in models: pivot = self.new_existing_pivot(self._clean_pivot_attributes(model)) model.set_relation("pivot", pivot)
Add the constraints for a relationship count query. :type query: orator.orm.Builder :type parent: orator.orm.Builder :rtype: orator.orm.Builder
def get_relation_count_query(self, query, parent): """ Add the constraints for a relationship count query. :type query: orator.orm.Builder :type parent: orator.orm.Builder :rtype: orator.orm.Builder """ if parent.get_query().from__ == query.get_query().from__: ...
Set the where clause for the relation query. :return: self :rtype: BelongsToMany
def _set_where(self): """ Set the where clause for the relation query. :return: self :rtype: BelongsToMany """ foreign = self.get_foreign_key() self._query.where(foreign, "=", self._parent.get_key()) return self
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 """ self._query.where_in(self.get_foreign_key(), self.get_keys(models))
Build model dictionary keyed by the relation's foreign key. :param results: The results :type results: Collection :rtype: dict
def _build_dictionary(self, results): """ Build model dictionary keyed by the relation's foreign key. :param results: The results :type results: Collection :rtype: dict """ foreign = self._foreign_key dictionary = {} for result in results: ...
Touch all of the related models of the relationship.
def touch(self): """ Touch all of the related models of the relationship. """ key = self.get_related().get_key_name() columns = self.get_related_fresh_update() ids = self.get_related_ids() if len(ids) > 0: self.get_related().new_query().where_in(key...
Get all of the IDs for the related models. :rtype: list
def get_related_ids(self): """ Get all of the IDs for the related models. :rtype: list """ related = self.get_related() full_key = related.get_qualified_key_name() return self.get_query().select(full_key).lists(related.get_key_name())
Save a list of new models and attach them to the parent model :type models: list :type joinings: dict :rtype: list
def save_many(self, models, joinings=None): """ Save a list of new models and attach them to the parent model :type models: list :type joinings: dict :rtype: list """ if joinings is None: joinings = {} for key, model in enumerate(models): ...
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 ...
Get the first related model record matching the attributes or create it. :param attributes: The attributes :type attributes: dict :rtype: Model
def first_or_create( self, _attributes=None, _joining=None, _touch=True, **attributes ): """ Get the first related model record matching the attributes or create it. :param attributes: The attributes :type attributes: dict :rtype: Model """ if _attr...
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, joining=None, touch=True): """ 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 ...
Create a new instance of the related model. :param attributes: The attributes :type attributes: dict :rtype: orator.orm.Model
def create(self, _attributes=None, _joining=None, _touch=True, **attributes): """ Create a new instance of the related model. :param attributes: The attributes :type attributes: dict :rtype: orator.orm.Model """ if _attributes is not None: attributes...
Create a list of new instances of the related model.
def create_many(self, records, joinings=None): """ Create a list of new instances of the related model. """ if joinings is None: joinings = [] instances = [] for key, record in enumerate(records): instances.append(self.create(record), joinings[ke...
Sync the intermediate tables with a list of IDs or collection of models
def sync(self, ids, detaching=True): """ Sync the intermediate tables with a list of IDs or collection of models """ changes = {"attached": [], "detached": [], "updated": []} if isinstance(ids, Collection): ids = ids.model_keys() current = self._new_pivot_qu...
Format the sync list so that it is keyed by ID.
def _format_sync_list(self, records): """ Format the sync list so that it is keyed by ID. """ results = {} for attributes in records: if not isinstance(attributes, dict): id, attributes = attributes, {} else: id = list(attr...
Attach a model to the parent.
def attach(self, id, attributes=None, touch=True): """ Attach a model to the parent. """ if isinstance(id, orator.orm.Model): id = id.get_key() query = self.new_pivot_statement() if not isinstance(id, list): id = [id] query.insert(self._...
Create a list of records to insert into the pivot table.
def _create_attach_records(self, ids, attributes): """ Create a list of records to insert into the pivot table. """ records = [] timed = self._has_pivot_column(self.created_at()) or self._has_pivot_column( self.updated_at() ) for key, value in enumer...
Create a full attachment record payload.
def _attacher(self, key, value, attributes, timed): """ Create a full attachment record payload. """ id, extra = self._get_attach_id(key, value, attributes) record = self._create_attach_record(id, timed) if extra: record.update(extra) return record
Get the attach record ID and extra attributes.
def _get_attach_id(self, key, value, attributes): """ Get the attach record ID and extra attributes. """ if isinstance(value, dict): key = list(value.keys())[0] attributes.update(value[key]) return [key, attributes] return value, attributes
Create a new pivot attachement record.
def _create_attach_record(self, id, timed): """ Create a new pivot attachement record. """ record = {} record[self._foreign_key] = self._parent.get_key() record[self._other_key] = id if timed: record = self._set_timestamps_on_attach(record) ...
Set the creation an update timestamps on an attach record.
def _set_timestamps_on_attach(self, record, exists=False): """ Set the creation an update timestamps on an attach record. """ fresh = self._parent.fresh_timestamp() if not exists and self._has_pivot_column(self.created_at()): record[self.created_at()] = fresh ...
Detach models from the relationship.
def detach(self, ids=None, touch=True): """ Detach models from the relationship. """ if isinstance(ids, orator.orm.model.Model): ids = ids.get_key() if ids is None: ids = [] query = self._new_pivot_query() if not isinstance(ids, list): ...
Touch if the parent model is being touched.
def touch_if_touching(self): """ Touch if the parent model is being touched. """ if self._touching_parent(): self.get_parent().touch() if self.get_parent().touches(self._relation_name): self.touch()
Create a new query builder for the pivot table. :rtype: orator.orm.Builder
def _new_pivot_query(self): """ Create a new query builder for the pivot table. :rtype: orator.orm.Builder """ query = self.new_pivot_statement() for where_args in self._pivot_wheres: query.where(*where_args) return query.where(self._foreign_key, se...
Create a new pivot model instance.
def new_pivot(self, attributes=None, exists=False): """ Create a new pivot model instance. """ pivot = self._related.new_pivot(self._parent, attributes, self._table, exists) return pivot.set_pivot_keys(self._foreign_key, self._other_key)
Set the columns on the pivot table to retrieve.
def with_pivot(self, *columns): """ Set the columns on the pivot table to retrieve. """ columns = list(columns) self._pivot_columns += columns return self
Specify that the pivot table has creation and update columns.
def with_timestamps(self, created_at=None, updated_at=None): """ Specify that the pivot table has creation and update columns. """ if not created_at: created_at = self.created_at() if not updated_at: updated_at = self.updated_at() return self.wit...
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: orator.connections.Connection :rtype: list
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...
Compile a create table command.
def compile_create(self, blueprint, command, _): """ Compile a create table command. """ columns = ", ".join(self._get_columns(blueprint)) return "CREATE TABLE %s (%s)" % (self.wrap_table(blueprint), columns)
Get the dbal column type. :param type_: The fluent type :type type_: str :rtype: str
def _get_dbal_column_type(self, type_): """ Get the dbal column type. :param type_: The fluent type :type type_: str :rtype: str """ type_ = type_.lower() if type_ == "enum": return "string" return super(PostgresSchemaGrammar, self)...
Set the where clause for the relation query. :return: self :rtype: BelongsToMany
def _set_where(self): """ Set the where clause for the relation query. :return: self :rtype: BelongsToMany """ super(MorphToMany, self)._set_where() self._query.where("%s.%s" % (self._table, self._morph_type), self._morph_name)
Create a new query builder for the pivot table. :rtype: orator.orm.Builder
def _new_pivot_query(self): """ Create a new query builder for the pivot table. :rtype: orator.orm.Builder """ query = super(MorphToMany, self)._new_pivot_query() return query.where(self._morph_type, self._morph_name)
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_key, self._other_key).set_morph_type( ...
Set the base constraints on the relation query. :rtype: None
def add_constraints(self): """ Set the base constraints on the relation query. :rtype: None """ if self._constraints: foreign_key = getattr(self._parent, self._foreign_key, None) if foreign_key is None: self._query = None else:...
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 """ key = "%s.%s" % (self._related.get_table(), self._other_key) self._query.where_in(key, self._get_eager_model_keys(models))
Gather the keys from a list of related models. :type models: list :rtype: list
def _get_eager_model_keys(self, models): """ Gather the keys from a list of related models. :type models: list :rtype: list """ keys = [] for model in models: value = getattr(model, self._foreign_key) if value is not None and value not ...
Initialize the relation on a set of models. :type models: list :type relation: str
def init_relation(self, models, relation): """ Initialize the relation on a set of models. :type models: list :type relation: str """ for model in models: model.set_relation(relation, Result(None, self, model)) return models
Update the parent model on the relationship. :param attributes: The update attributes :type attributes: dict :rtype: mixed
def update(self, _attributes=None, **attributes): """ Update the parent model on the relationship. :param attributes: The update attributes :type attributes: dict :rtype: mixed """ if _attributes is not None: attributes.update(_attributes) i...
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 """ self._models = Collection.make(models) self._build_dictionary(models)
Build a dictionary with the models. :param models: The models :type models: Collection
def _build_dictionary(self, models): """ Build a dictionary with the models. :param models: The models :type models: Collection """ for model in models: key = getattr(model, self._morph_type, None) if key: foreign = getattr(model, ...
Associate the model instance to the given parent. :type model: orator.Model :rtype: orator.Model
def associate(self, model): """ Associate the model instance to the given parent. :type model: orator.Model :rtype: orator.Model """ self._parent.set_attribute(self._foreign_key, model.get_key()) self._parent.set_attribute(self._morph_type, model.get_morph_name(...
Get the relationship for eager loading. :rtype: Collection
def get_eager(self): """ Get the relationship for eager loading. :rtype: Collection """ for type in self._dictionary.keys(): self._match_to_morph_parents(type, self._get_results_by_type(type)) return self._models
Match the results for a given type to their parent. :param type: The parent type :type type: str :param results: The results to match to their parent :type results: Collection
def _match_to_morph_parents(self, type, results): """ Match the results for a given type to their parent. :param type: The parent type :type type: str :param results: The results to match to their parent :type results: Collection """ for result in result...
Get all the relation results for a type. :param type: The type :type type: str :rtype: Collection
def _get_results_by_type(self, type): """ Get all the relation results for a type. :param type: The type :type type: str :rtype: Collection """ instance = self._create_model_by_type(type) key = instance.get_key_name() query = instance.new_query...
Gather all of the foreign keys for a given type. :param type: The type :type type: str :rtype: BaseCollection
def _gather_keys_by_type(self, type): """ Gather all of the foreign keys for a given type. :param type: The type :type type: str :rtype: BaseCollection """ foreign = self._foreign_key keys = ( BaseCollection.make(list(self._dictionary[type]....
Set the primary key. :type columns: list :type index_name: str or bool :rtype: Table
def set_primary_key(self, columns, index_name=False): """ Set the primary key. :type columns: list :type index_name: str or bool :rtype: Table """ self._add_index( self._create_index(columns, index_name or "primary", True, True) ) fo...
Drops an index from this table. :param name: The index name :type name: str
def drop_index(self, name): """ Drops an index from this table. :param name: The index name :type name: str """ name = self._normalize_identifier(name) if not self.has_index(name): raise IndexDoesNotExist(name, self._name) del self._indexes[n...
Renames an index. :param old_name: The name of the index to rename from. :type old_name: str :param new_name: The name of the index to rename to. :type new_name: str or None :rtype: Table
def rename_index(self, old_name, new_name=None): """ Renames an index. :param old_name: The name of the index to rename from. :type old_name: str :param new_name: The name of the index to rename to. :type new_name: str or None :rtype: Table """ ...
Checks if an index begins in the order of the given columns. :type columns: list :rtype: bool
def columns_are_indexed(self, columns): """ Checks if an index begins in the order of the given columns. :type columns: list :rtype: bool """ for index in self._indexes.values(): if index.spans_columns(columns): return True return Fa...
Creates an Index instance. :param columns: The index columns :type columns: list :param name: The index name :type name: str :param is_unique: Whether the index is unique or not :type is_unique: bool :param is_primary: Whether the index is primary or not ...
def _create_index( self, columns, name, is_unique, is_primary, flags=None, options=None ): """ Creates an Index instance. :param columns: The index columns :type columns: list :param name: The index name :type name: str :param is_unique: Whether the...
Adds a new column. :param name: The column name :type name: str :param type_name: The column type :type type_name: str :param options: The column options :type options: dict :rtype: Column
def add_column(self, name, type_name, options=None): """ Adds a new column. :param name: The column name :type name: str :param type_name: The column type :type type_name: str :param options: The column options :type options: dict :rtype: Colum...
Changes column details. :param name: The column to change. :type name: str :param options: The new options. :type options: str :rtype: Table
def change_column(self, name, options): """ Changes column details. :param name: The column to change. :type name: str :param options: The new options. :type options: str :rtype: Table """ column = self.get_column(name) column.set_option...
Drops a Column from the Table :param name: The name of the column :type name: str :rtype: Table
def drop_column(self, name): """ Drops a Column from the Table :param name: The name of the column :type name: str :rtype: Table """ name = self._normalize_identifier(name) del self._columns[name] return self
Adds a foreign key constraint. Name is inferred from the local columns. :param foreign_table: Table instance or table name :type foreign_table: Table or str :type local_columns: list :type foreign_columns: list :type options: dict :type constraint_name: str ...
def add_foreign_key_constraint( self, foreign_table, local_columns, foreign_columns, options=None, constraint_name=None, ): """ Adds a foreign key constraint. Name is inferred from the local columns. :param foreign_table: Table instan...
Adds a foreign key constraint with a given name. :param name: The constraint name :type name: str :param foreign_table: Table instance or table name :type foreign_table: Table or str :type local_columns: list :type foreign_columns: list :type options: dict ...
def add_named_foreign_key_constraint( self, name, foreign_table, local_columns, foreign_columns, options ): """ Adds a foreign key constraint with a given name. :param name: The constraint name :type name: str :param foreign_table: Table instance or table name ...
Adds an index to the table. :param index: The index to add :type index: Index :rtype: Table
def _add_index(self, index): """ Adds an index to the table. :param index: The index to add :type index: Index :rtype: Table """ index_name = index.get_name() index_name = self._normalize_identifier(index_name) replaced_implicit_indexes = [] ...
Adds a foreign key constraint. :param constraint: The constraint to add :type constraint: ForeignKeyConstraint :rtype: Table
def _add_foreign_key_constraint(self, constraint): """ Adds a foreign key constraint. :param constraint: The constraint to add :type constraint: ForeignKeyConstraint :rtype: Table """ constraint.set_local_table(self) if constraint.get_name(): ...
Returns whether this table has a foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: bool
def has_foreign_key(self, name): """ Returns whether this table has a foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: bool """ name = self._normalize_identifier(name) return name in self._fk_constrain...
Returns the foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: ForeignKeyConstraint
def get_foreign_key(self, name): """ Returns the foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: ForeignKeyConstraint """ name = self._normalize_identifier(name) if not self.has_foreign_key(name): ...
Removes the foreign key constraint with the given name. :param name: The constraint name :type name: str
def remove_foreign_key(self, name): """ Removes the foreign key constraint with the given name. :param name: The constraint name :type name: str """ name = self._normalize_identifier(name) if not self.has_foreign_key(name): raise ForeignKeyDoesNotExi...
Returns the primary key columns. :rtype: list
def get_primary_key_columns(self): """ Returns the primary key columns. :rtype: list """ if not self.has_primary_key(): raise DBALException('Table "%s" has no primary key.' % self.get_name()) return self.get_primary_key().get_columns()
Returns whether this table has an Index with the given name. :param name: The index name :type name: str :rtype: bool
def has_index(self, name): """ Returns whether this table has an Index with the given name. :param name: The index name :type name: str :rtype: bool """ name = self._normalize_identifier(name) return name in self._indexes
Returns the Index with the given name. :param name: The index name :type name: str :rtype: Index
def get_index(self, name): """ Returns the Index with the given name. :param name: The index name :type name: str :rtype: Index """ name = self._normalize_identifier(name) if not self.has_index(name): raise IndexDoesNotExist(name, self._name)...
Set the keys for a save update query. :param query: A Builder instance :type query: orator.orm.Builder :return: The Builder instance :rtype: orator.orm.Builder
def _set_keys_for_save_query(self, query): """ Set the keys for a save update query. :param query: A Builder instance :type query: orator.orm.Builder :return: The Builder instance :rtype: orator.orm.Builder """ query.where(self._morph_type, self._morph_n...
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_name) return query.delete()
Remove a registered global scope. :param scope: The scope to remove :type scope: Scope or str :rtype: Builder
def without_global_scope(self, scope): """ Remove a registered global scope. :param scope: The scope to remove :type scope: Scope or str :rtype: Builder """ if isinstance(scope, basestring): del self._scopes[scope] return self k...
Find a model by its primary key :param id: The primary key value :type id: mixed :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Model
def find(self, id, columns=None): """ Find a model by its primary key :param id: The primary key value :type id: mixed :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Model """ if colum...
Find a model by its primary key :param id: The primary key values :type id: list :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Collection
def find_many(self, id, columns=None): """ Find a model by its primary key :param id: The primary key values :type id: list :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Collection """ ...
Find a model by its primary key or raise an exception :param id: The primary key value :type id: mixed :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Model :raises: ModelNotFound
def find_or_fail(self, id, columns=None): """ Find a model by its primary key or raise an exception :param id: The primary key value :type id: mixed :param columns: The columns to retrieve :type columns: list :return: The found model :rtype: orator.Mode...
Execute the query and get the first result or raise an exception :param columns: The columns to get :type columns: list :return: The result :rtype: mixed
def first_or_fail(self, columns=None): """ Execute the query and get the first result or raise an exception :param columns: The columns to get :type columns: list :return: The result :rtype: mixed """ model = self.first(columns) if model is not ...
Execute the query as a "select" statement. :param columns: The columns to get :type columns: list :rtype: orator.Collection
def get(self, columns=None): """ Execute the query as a "select" statement. :param columns: The columns to get :type columns: list :rtype: orator.Collection """ models = self.get_models(columns) # If we actually found models we will also eager load any ...
Pluck a single column from the database. :param column: THe column to pluck :type column: str :return: The column value :rtype: mixed
def pluck(self, column): """ Pluck a single column from the database. :param column: THe column to pluck :type column: str :return: The column value :rtype: mixed """ result = self.first([column]) if result: return result[column]
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 """ connection = self._model.get_connection_name() for results in self.apply_scopes().get_query().chu...
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
def paginate(self, per_page=None, 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 co...
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
def simple_paginate(self, per_page=None, 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:...
Update a record in the database :param values: The values of the update :type values: dict :return: The number of records affected :rtype: int
def update(self, _values=None, **values): """ Update a record in the database :param values: The values of the update :type values: dict :return: The number of records affected :rtype: int """ if _values is not None: values.update(_values) ...
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 ...
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 ...
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 ...
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 ...
Add the "updated_at" column to a dictionary of values. :param values: The values to update :type values: dict :return: The new dictionary of values :rtype: dict
def _add_updated_at_column(self, values): """ Add the "updated_at" column to a dictionary of values. :param values: The values to update :type values: dict :return: The new dictionary of values :rtype: dict """ if not self._model.uses_timestamps(): ...
Delete a record from the database.
def delete(self): """ Delete a record from the database. """ if self._on_delete is not None: return self._on_delete(self) return self._query.delete()
Get the hydrated models without eager loading. :param columns: The columns to get :type columns: list :return: A list of models :rtype: orator.orm.collection.Collection
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: orator.orm.collection.Collection """ results = self.apply_scopes().get_query()...
Get the relation instance for the given relation name. :rtype: orator.orm.relations.Relation
def get_relation(self, relation): """ Get the relation instance for the given relation name. :rtype: orator.orm.relations.Relation """ from .relations import Relation with Relation.no_constraints(True): rel = getattr(self.get_model(), relation)() ne...
Get the deeply nested relations for a given top-level relation. :rtype: dict
def _nested_relations(self, relation): """ Get the deeply nested relations for a given top-level relation. :rtype: dict """ nested = {} for name, constraints in self._eager_load.items(): if self._is_nested(name, relation): nested[name[len(rel...
Determine if the relationship is nested. :type name: str :type relation: str :rtype: bool
def _is_nested(self, name, relation): """ Determine if the relationship is nested. :type name: str :type relation: str :rtype: bool """ dots = name.find(".") return dots and name.startswith(relation + ".")
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|Builder :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|Builder :param operator: The operator of the where clause ...
Add an exists clause to the query. :param query: The exists query :type query: Builder or QueryBuilder :type boolean: str :type negate: bool :rtype: Builder
def where_exists(self, query, boolean="and", negate=False): """ Add an exists clause to the query. :param query: The exists query :type query: Builder or QueryBuilder :type boolean: str :type negate: bool :rtype: Builder """ if isinstance(query...
Add a relationship count condition to the query. :param relation: The relation to count :type relation: str :param operator: The operator :type operator: str :param count: The count :type count: int :param boolean: The boolean value :type boolean: str ...
def has(self, relation, operator=">=", count=1, boolean="and", extra=None): """ Add a relationship count condition to the query. :param relation: The relation to count :type relation: str :param operator: The operator :type operator: str :param count: The count...
Add the "has" condition where clause to the query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.relations.Relation :param operator: The operator :type operator: str :param count: The...
def _add_has_where(self, has_query, relation, operator, count, boolean): """ Add the "has" condition where clause to the query. :param has_query: The has query :type has_query: Builder :param relation: The relation to count :type relation: orator.orm.relations.Relation ...