repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
sdispater/orator
orator/orm/relations/belongs_to.py
BelongsTo.update
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) instance = self.get_results() return instance.fill(attributes).save()
python
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) instance = self.get_results() return instance.fill(attributes).save()
[ "def", "update", "(", "self", ",", "_attributes", "=", "None", ",", "*", "*", "attributes", ")", ":", "if", "_attributes", "is", "not", "None", ":", "attributes", ".", "update", "(", "_attributes", ")", "instance", "=", "self", ".", "get_results", "(", ...
Update the parent model on the relationship. :param attributes: The update attributes :type attributes: dict :rtype: mixed
[ "Update", "the", "parent", "model", "on", "the", "relationship", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/belongs_to.py#L177-L191
train
225,800
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._build_dictionary
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, self._foreign_key) if key not in self._dictionary: self._dictionary[key] = {} if foreign not in self._dictionary[key]: self._dictionary[key][foreign] = [] self._dictionary[key][foreign].append(model)
python
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, self._foreign_key) if key not in self._dictionary: self._dictionary[key] = {} if foreign not in self._dictionary[key]: self._dictionary[key][foreign] = [] self._dictionary[key][foreign].append(model)
[ "def", "_build_dictionary", "(", "self", ",", "models", ")", ":", "for", "model", "in", "models", ":", "key", "=", "getattr", "(", "model", ",", "self", ".", "_morph_type", ",", "None", ")", "if", "key", ":", "foreign", "=", "getattr", "(", "model", ...
Build a dictionary with the models. :param models: The models :type models: Collection
[ "Build", "a", "dictionary", "with", "the", "models", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L49-L66
train
225,801
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo.get_eager
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
python
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
[ "def", "get_eager", "(", "self", ")", ":", "for", "type", "in", "self", ".", "_dictionary", ".", "keys", "(", ")", ":", "self", ".", "_match_to_morph_parents", "(", "type", ",", "self", ".", "_get_results_by_type", "(", "type", ")", ")", "return", "self"...
Get the relationship for eager loading. :rtype: Collection
[ "Get", "the", "relationship", "for", "eager", "loading", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L93-L102
train
225,802
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._match_to_morph_parents
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 results: if result.get_key() in self._dictionary.get(type, []): for model in self._dictionary[type][result.get_key()]: model.set_relation( self._relation, Result(result, self, model, related=result) )
python
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 results: if result.get_key() in self._dictionary.get(type, []): for model in self._dictionary[type][result.get_key()]: model.set_relation( self._relation, Result(result, self, model, related=result) )
[ "def", "_match_to_morph_parents", "(", "self", ",", "type", ",", "results", ")", ":", "for", "result", "in", "results", ":", "if", "result", ".", "get_key", "(", ")", "in", "self", ".", "_dictionary", ".", "get", "(", "type", ",", "[", "]", ")", ":",...
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
[ "Match", "the", "results", "for", "a", "given", "type", "to", "their", "parent", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L104-L119
train
225,803
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._get_results_by_type
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() query = self._use_with_trashed(query) return query.where_in(key, self._gather_keys_by_type(type).all()).get()
python
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() query = self._use_with_trashed(query) return query.where_in(key, self._gather_keys_by_type(type).all()).get()
[ "def", "_get_results_by_type", "(", "self", ",", "type", ")", ":", "instance", "=", "self", ".", "_create_model_by_type", "(", "type", ")", "key", "=", "instance", ".", "get_key_name", "(", ")", "query", "=", "instance", ".", "new_query", "(", ")", "query"...
Get all the relation results for a type. :param type: The type :type type: str :rtype: Collection
[ "Get", "all", "the", "relation", "results", "for", "a", "type", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L121-L138
train
225,804
sdispater/orator
orator/orm/relations/morph_to.py
MorphTo._gather_keys_by_type
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].values())) .map(lambda models: getattr(models[0], foreign)) .unique() ) return keys
python
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].values())) .map(lambda models: getattr(models[0], foreign)) .unique() ) return keys
[ "def", "_gather_keys_by_type", "(", "self", ",", "type", ")", ":", "foreign", "=", "self", ".", "_foreign_key", "keys", "=", "(", "BaseCollection", ".", "make", "(", "list", "(", "self", ".", "_dictionary", "[", "type", "]", ".", "values", "(", ")", ")...
Gather all of the foreign keys for a given type. :param type: The type :type type: str :rtype: BaseCollection
[ "Gather", "all", "of", "the", "foreign", "keys", "for", "a", "given", "type", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/morph_to.py#L140-L157
train
225,805
sdispater/orator
orator/dbal/table.py
Table.set_primary_key
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) ) for column_name in columns: column = self.get_column(column_name) column.set_notnull(True) return self
python
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) ) for column_name in columns: column = self.get_column(column_name) column.set_notnull(True) return self
[ "def", "set_primary_key", "(", "self", ",", "columns", ",", "index_name", "=", "False", ")", ":", "self", ".", "_add_index", "(", "self", ".", "_create_index", "(", "columns", ",", "index_name", "or", "\"primary\"", ",", "True", ",", "True", ")", ")", "f...
Set the primary key. :type columns: list :type index_name: str or bool :rtype: Table
[ "Set", "the", "primary", "key", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L55-L72
train
225,806
sdispater/orator
orator/dbal/table.py
Table.drop_index
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[name]
python
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[name]
[ "def", "drop_index", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_index", "(", "name", ")", ":", "raise", "IndexDoesNotExist", "(", "name", ",", "self", ".", "_n...
Drops an index from this table. :param name: The index name :type name: str
[ "Drops", "an", "index", "from", "this", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L91-L102
train
225,807
sdispater/orator
orator/dbal/table.py
Table.rename_index
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 """ old_name = self._normalize_identifier(old_name) normalized_new_name = self._normalize_identifier(new_name) if old_name == normalized_new_name: return self if not self.has_index(old_name): raise IndexDoesNotExist(old_name, self._name) if self.has_index(normalized_new_name): raise IndexAlreadyExists(normalized_new_name, self._name) old_index = self._indexes[old_name] if old_index.is_primary(): self.drop_primary_key() return self.set_primary_key(old_index.get_columns(), new_name) del self._indexes[old_name] if old_index.is_unique(): return self.add_unique_index(old_index.get_columns(), new_name) return self.add_index(old_index.get_columns(), new_name, old_index.get_flags())
python
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 """ old_name = self._normalize_identifier(old_name) normalized_new_name = self._normalize_identifier(new_name) if old_name == normalized_new_name: return self if not self.has_index(old_name): raise IndexDoesNotExist(old_name, self._name) if self.has_index(normalized_new_name): raise IndexAlreadyExists(normalized_new_name, self._name) old_index = self._indexes[old_name] if old_index.is_primary(): self.drop_primary_key() return self.set_primary_key(old_index.get_columns(), new_name) del self._indexes[old_name] if old_index.is_unique(): return self.add_unique_index(old_index.get_columns(), new_name) return self.add_index(old_index.get_columns(), new_name, old_index.get_flags())
[ "def", "rename_index", "(", "self", ",", "old_name", ",", "new_name", "=", "None", ")", ":", "old_name", "=", "self", ".", "_normalize_identifier", "(", "old_name", ")", "normalized_new_name", "=", "self", ".", "_normalize_identifier", "(", "new_name", ")", "i...
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
[ "Renames", "an", "index", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L114-L150
train
225,808
sdispater/orator
orator/dbal/table.py
Table.columns_are_indexed
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 False
python
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 False
[ "def", "columns_are_indexed", "(", "self", ",", "columns", ")", ":", "for", "index", "in", "self", ".", "_indexes", ".", "values", "(", ")", ":", "if", "index", ".", "spans_columns", "(", "columns", ")", ":", "return", "True", "return", "False" ]
Checks if an index begins in the order of the given columns. :type columns: list :rtype: bool
[ "Checks", "if", "an", "index", "begins", "in", "the", "order", "of", "the", "given", "columns", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L152-L164
train
225,809
sdispater/orator
orator/dbal/table.py
Table._create_index
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 index is unique or not :type is_unique: bool :param is_primary: Whether the index is primary or not :type is_primary: bool :param flags: The index flags :type: dict :param options: The options :type options: dict :rtype: Index """ if re.match("[^a-zA-Z0-9_]+", self._normalize_identifier(name)): raise IndexNameInvalid(name) for column in columns: if isinstance(column, dict): column = list(column.keys())[0] if not self.has_column(column): raise ColumnDoesNotExist(column, self._name) return Index(name, columns, is_unique, is_primary, flags, options)
python
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 index is unique or not :type is_unique: bool :param is_primary: Whether the index is primary or not :type is_primary: bool :param flags: The index flags :type: dict :param options: The options :type options: dict :rtype: Index """ if re.match("[^a-zA-Z0-9_]+", self._normalize_identifier(name)): raise IndexNameInvalid(name) for column in columns: if isinstance(column, dict): column = list(column.keys())[0] if not self.has_column(column): raise ColumnDoesNotExist(column, self._name) return Index(name, columns, is_unique, is_primary, flags, options)
[ "def", "_create_index", "(", "self", ",", "columns", ",", "name", ",", "is_unique", ",", "is_primary", ",", "flags", "=", "None", ",", "options", "=", "None", ")", ":", "if", "re", ".", "match", "(", "\"[^a-zA-Z0-9_]+\"", ",", "self", ".", "_normalize_id...
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 :type is_primary: bool :param flags: The index flags :type: dict :param options: The options :type options: dict :rtype: Index
[ "Creates", "an", "Index", "instance", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L166-L202
train
225,810
sdispater/orator
orator/dbal/table.py
Table.add_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: Column """ column = Column(name, type_name, options) self._add_column(column) return column
python
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: Column """ column = Column(name, type_name, options) self._add_column(column) return column
[ "def", "add_column", "(", "self", ",", "name", ",", "type_name", ",", "options", "=", "None", ")", ":", "column", "=", "Column", "(", "name", ",", "type_name", ",", "options", ")", "self", ".", "_add_column", "(", "column", ")", "return", "column" ]
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
[ "Adds", "a", "new", "column", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L204-L223
train
225,811
sdispater/orator
orator/dbal/table.py
Table.change_column
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_options(options) return self
python
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_options(options) return self
[ "def", "change_column", "(", "self", ",", "name", ",", "options", ")", ":", "column", "=", "self", ".", "get_column", "(", "name", ")", "column", ".", "set_options", "(", "options", ")", "return", "self" ]
Changes column details. :param name: The column to change. :type name: str :param options: The new options. :type options: str :rtype: Table
[ "Changes", "column", "details", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L225-L240
train
225,812
sdispater/orator
orator/dbal/table.py
Table.drop_column
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
python
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
[ "def", "drop_column", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "del", "self", ".", "_columns", "[", "name", "]", "return", "self" ]
Drops a Column from the Table :param name: The name of the column :type name: str :rtype: Table
[ "Drops", "a", "Column", "from", "the", "Table" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L242-L254
train
225,813
sdispater/orator
orator/dbal/table.py
Table.add_named_foreign_key_constraint
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 :type foreign_table: Table or str :type local_columns: list :type foreign_columns: list :type options: dict :rtype: Table """ if isinstance(foreign_table, Table): for column in foreign_columns: if not foreign_table.has_column(column): raise ColumnDoesNotExist(column, foreign_table.get_name()) for column in local_columns: if not self.has_column(column): raise ColumnDoesNotExist(column, self._name) constraint = ForeignKeyConstraint( local_columns, foreign_table, foreign_columns, name, options ) self._add_foreign_key_constraint(constraint) return self
python
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 :type foreign_table: Table or str :type local_columns: list :type foreign_columns: list :type options: dict :rtype: Table """ if isinstance(foreign_table, Table): for column in foreign_columns: if not foreign_table.has_column(column): raise ColumnDoesNotExist(column, foreign_table.get_name()) for column in local_columns: if not self.has_column(column): raise ColumnDoesNotExist(column, self._name) constraint = ForeignKeyConstraint( local_columns, foreign_table, foreign_columns, name, options ) self._add_foreign_key_constraint(constraint) return self
[ "def", "add_named_foreign_key_constraint", "(", "self", ",", "name", ",", "foreign_table", ",", "local_columns", ",", "foreign_columns", ",", "options", ")", ":", "if", "isinstance", "(", "foreign_table", ",", "Table", ")", ":", "for", "column", "in", "foreign_c...
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 :rtype: Table
[ "Adds", "a", "foreign", "key", "constraint", "with", "a", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L293-L328
train
225,814
sdispater/orator
orator/dbal/table.py
Table._add_index
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 = [] for name, implicit_index in self._implicit_indexes.items(): if implicit_index.is_fullfilled_by(index) and name in self._indexes: replaced_implicit_indexes.append(name) already_exists = ( index_name in self._indexes and index_name not in replaced_implicit_indexes or self._primary_key_name is not False and index.is_primary() ) if already_exists: raise IndexAlreadyExists(index_name, self._name) for name in replaced_implicit_indexes: del self._indexes[name] del self._implicit_indexes[name] if index.is_primary(): self._primary_key_name = index_name self._indexes[index_name] = index return self
python
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 = [] for name, implicit_index in self._implicit_indexes.items(): if implicit_index.is_fullfilled_by(index) and name in self._indexes: replaced_implicit_indexes.append(name) already_exists = ( index_name in self._indexes and index_name not in replaced_implicit_indexes or self._primary_key_name is not False and index.is_primary() ) if already_exists: raise IndexAlreadyExists(index_name, self._name) for name in replaced_implicit_indexes: del self._indexes[name] del self._implicit_indexes[name] if index.is_primary(): self._primary_key_name = index_name self._indexes[index_name] = index return self
[ "def", "_add_index", "(", "self", ",", "index", ")", ":", "index_name", "=", "index", ".", "get_name", "(", ")", "index_name", "=", "self", ".", "_normalize_identifier", "(", "index_name", ")", "replaced_implicit_indexes", "=", "[", "]", "for", "name", ",", ...
Adds an index to the table. :param index: The index to add :type index: Index :rtype: Table
[ "Adds", "an", "index", "to", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L343-L378
train
225,815
sdispater/orator
orator/dbal/table.py
Table.has_foreign_key
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_constraints
python
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_constraints
[ "def", "has_foreign_key", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "return", "name", "in", "self", ".", "_fk_constraints" ]
Returns whether this table has a foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: bool
[ "Returns", "whether", "this", "table", "has", "a", "foreign", "key", "constraint", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L428-L439
train
225,816
sdispater/orator
orator/dbal/table.py
Table.get_foreign_key
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): raise ForeignKeyDoesNotExist(name, self._name) return self._fk_constraints[name]
python
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): raise ForeignKeyDoesNotExist(name, self._name) return self._fk_constraints[name]
[ "def", "get_foreign_key", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_foreign_key", "(", "name", ")", ":", "raise", "ForeignKeyDoesNotExist", "(", "name", ",", "sel...
Returns the foreign key constraint with the given name. :param name: The constraint name :type name: str :rtype: ForeignKeyConstraint
[ "Returns", "the", "foreign", "key", "constraint", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L441-L455
train
225,817
sdispater/orator
orator/dbal/table.py
Table.remove_foreign_key
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 ForeignKeyDoesNotExist(name, self._name) del self._fk_constraints[name]
python
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 ForeignKeyDoesNotExist(name, self._name) del self._fk_constraints[name]
[ "def", "remove_foreign_key", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_foreign_key", "(", "name", ")", ":", "raise", "ForeignKeyDoesNotExist", "(", "name", ",", "...
Removes the foreign key constraint with the given name. :param name: The constraint name :type name: str
[ "Removes", "the", "foreign", "key", "constraint", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L457-L469
train
225,818
sdispater/orator
orator/dbal/table.py
Table.get_primary_key_columns
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()
python
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()
[ "def", "get_primary_key_columns", "(", "self", ")", ":", "if", "not", "self", ".", "has_primary_key", "(", ")", ":", "raise", "DBALException", "(", "'Table \"%s\" has no primary key.'", "%", "self", ".", "get_name", "(", ")", ")", "return", "self", ".", "get_p...
Returns the primary key columns. :rtype: list
[ "Returns", "the", "primary", "key", "columns", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L511-L520
train
225,819
sdispater/orator
orator/dbal/table.py
Table.has_index
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
python
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
[ "def", "has_index", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "return", "name", "in", "self", ".", "_indexes" ]
Returns whether this table has an Index with the given name. :param name: The index name :type name: str :rtype: bool
[ "Returns", "whether", "this", "table", "has", "an", "Index", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L533-L544
train
225,820
sdispater/orator
orator/dbal/table.py
Table.get_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) return self._indexes[name]
python
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) return self._indexes[name]
[ "def", "get_index", "(", "self", ",", "name", ")", ":", "name", "=", "self", ".", "_normalize_identifier", "(", "name", ")", "if", "not", "self", ".", "has_index", "(", "name", ")", ":", "raise", "IndexDoesNotExist", "(", "name", ",", "self", ".", "_na...
Returns the Index with the given name. :param name: The index name :type name: str :rtype: Index
[ "Returns", "the", "Index", "with", "the", "given", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/table.py#L546-L559
train
225,821
sdispater/orator
orator/orm/builder.py
Builder.without_global_scope
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 keys = [] for key, value in self._scopes.items(): if scope == value.__class__ or isinstance(scope, value.__class__): keys.append(key) for key in keys: del self._scopes[key] return self
python
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 keys = [] for key, value in self._scopes.items(): if scope == value.__class__ or isinstance(scope, value.__class__): keys.append(key) for key in keys: del self._scopes[key] return self
[ "def", "without_global_scope", "(", "self", ",", "scope", ")", ":", "if", "isinstance", "(", "scope", ",", "basestring", ")", ":", "del", "self", ".", "_scopes", "[", "scope", "]", "return", "self", "keys", "=", "[", "]", "for", "key", ",", "value", ...
Remove a registered global scope. :param scope: The scope to remove :type scope: Scope or str :rtype: Builder
[ "Remove", "a", "registered", "global", "scope", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L63-L85
train
225,822
sdispater/orator
orator/orm/builder.py
Builder.find_or_fail
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.Model :raises: ModelNotFound """ result = self.find(id, columns) if isinstance(id, list): if len(result) == len(set(id)): return result elif result: return result raise ModelNotFound(self._model.__class__)
python
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.Model :raises: ModelNotFound """ result = self.find(id, columns) if isinstance(id, list): if len(result) == len(set(id)): return result elif result: return result raise ModelNotFound(self._model.__class__)
[ "def", "find_or_fail", "(", "self", ",", "id", ",", "columns", "=", "None", ")", ":", "result", "=", "self", ".", "find", "(", "id", ",", "columns", ")", "if", "isinstance", "(", "id", ",", "list", ")", ":", "if", "len", "(", "result", ")", "==",...
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
[ "Find", "a", "model", "by", "its", "primary", "key", "or", "raise", "an", "exception" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L143-L166
train
225,823
sdispater/orator
orator/orm/builder.py
Builder.first_or_fail
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 None: return model raise ModelNotFound(self._model.__class__)
python
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 None: return model raise ModelNotFound(self._model.__class__)
[ "def", "first_or_fail", "(", "self", ",", "columns", "=", "None", ")", ":", "model", "=", "self", ".", "first", "(", "columns", ")", "if", "model", "is", "not", "None", ":", "return", "model", "raise", "ModelNotFound", "(", "self", ".", "_model", ".", ...
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
[ "Execute", "the", "query", "and", "get", "the", "first", "result", "or", "raise", "an", "exception" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L183-L198
train
225,824
sdispater/orator
orator/orm/builder.py
Builder.pluck
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]
python
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]
[ "def", "pluck", "(", "self", ",", "column", ")", ":", "result", "=", "self", ".", "first", "(", "[", "column", "]", ")", "if", "result", ":", "return", "result", "[", "column", "]" ]
Pluck a single column from the database. :param column: THe column to pluck :type column: str :return: The column value :rtype: mixed
[ "Pluck", "a", "single", "column", "from", "the", "database", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L221-L234
train
225,825
sdispater/orator
orator/orm/builder.py
Builder._add_updated_at_column
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(): return values column = self._model.get_updated_at_column() if "updated_at" not in values: values.update({column: self._model.fresh_timestamp_string()}) return values
python
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(): return values column = self._model.get_updated_at_column() if "updated_at" not in values: values.update({column: self._model.fresh_timestamp_string()}) return values
[ "def", "_add_updated_at_column", "(", "self", ",", "values", ")", ":", "if", "not", "self", ".", "_model", ".", "uses_timestamps", "(", ")", ":", "return", "values", "column", "=", "self", ".", "_model", ".", "get_updated_at_column", "(", ")", "if", "\"upd...
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
[ "Add", "the", "updated_at", "column", "to", "a", "dictionary", "of", "values", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L401-L419
train
225,826
sdispater/orator
orator/orm/builder.py
Builder.delete
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()
python
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()
[ "def", "delete", "(", "self", ")", ":", "if", "self", ".", "_on_delete", "is", "not", "None", ":", "return", "self", ".", "_on_delete", "(", "self", ")", "return", "self", ".", "_query", ".", "delete", "(", ")" ]
Delete a record from the database.
[ "Delete", "a", "record", "from", "the", "database", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L421-L428
train
225,827
sdispater/orator
orator/orm/builder.py
Builder.get_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)() nested = self._nested_relations(relation) if len(nested) > 0: rel.get_query().with_(nested) return rel
python
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)() nested = self._nested_relations(relation) if len(nested) > 0: rel.get_query().with_(nested) return rel
[ "def", "get_relation", "(", "self", ",", "relation", ")", ":", "from", ".", "relations", "import", "Relation", "with", "Relation", ".", "no_constraints", "(", "True", ")", ":", "rel", "=", "getattr", "(", "self", ".", "get_model", "(", ")", ",", "relatio...
Get the relation instance for the given relation name. :rtype: orator.orm.relations.Relation
[ "Get", "the", "relation", "instance", "for", "the", "given", "relation", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L500-L516
train
225,828
sdispater/orator
orator/orm/builder.py
Builder._nested_relations
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(relation + ".") :]] = constraints return nested
python
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(relation + ".") :]] = constraints return nested
[ "def", "_nested_relations", "(", "self", ",", "relation", ")", ":", "nested", "=", "{", "}", "for", "name", ",", "constraints", "in", "self", ".", "_eager_load", ".", "items", "(", ")", ":", "if", "self", ".", "_is_nested", "(", "name", ",", "relation"...
Get the deeply nested relations for a given top-level relation. :rtype: dict
[ "Get", "the", "deeply", "nested", "relations", "for", "a", "given", "top", "-", "level", "relation", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L518-L530
train
225,829
sdispater/orator
orator/orm/builder.py
Builder._is_nested
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 + ".")
python
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 + ".")
[ "def", "_is_nested", "(", "self", ",", "name", ",", "relation", ")", ":", "dots", "=", "name", ".", "find", "(", "\".\"", ")", "return", "dots", "and", "name", ".", "startswith", "(", "relation", "+", "\".\"", ")" ]
Determine if the relationship is nested. :type name: str :type relation: str :rtype: bool
[ "Determine", "if", "the", "relationship", "is", "nested", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L532-L543
train
225,830
sdispater/orator
orator/orm/builder.py
Builder.where_exists
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, Builder): query = query.get_query() self.get_query().where_exists(query, boolean, negate) return self
python
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, Builder): query = query.get_query() self.get_query().where_exists(query, boolean, negate) return self
[ "def", "where_exists", "(", "self", ",", "query", ",", "boolean", "=", "\"and\"", ",", "negate", "=", "False", ")", ":", "if", "isinstance", "(", "query", ",", "Builder", ")", ":", "query", "=", "query", ".", "get_query", "(", ")", "self", ".", "get_...
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
[ "Add", "an", "exists", "clause", "to", "the", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L589-L607
train
225,831
sdispater/orator
orator/orm/builder.py
Builder.has
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 :type count: int :param boolean: The boolean value :type boolean: str :param extra: The extra query :type extra: Builder or callable :type: Builder """ if relation.find(".") >= 0: return self._has_nested(relation, operator, count, boolean, extra) relation = self._get_has_relation_query(relation) query = relation.get_relation_count_query( relation.get_related().new_query(), self ) # TODO: extra query if extra: if callable(extra): extra(query) return self._add_has_where( query.apply_scopes(), relation, operator, count, boolean )
python
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 :type count: int :param boolean: The boolean value :type boolean: str :param extra: The extra query :type extra: Builder or callable :type: Builder """ if relation.find(".") >= 0: return self._has_nested(relation, operator, count, boolean, extra) relation = self._get_has_relation_query(relation) query = relation.get_relation_count_query( relation.get_related().new_query(), self ) # TODO: extra query if extra: if callable(extra): extra(query) return self._add_has_where( query.apply_scopes(), relation, operator, count, boolean )
[ "def", "has", "(", "self", ",", "relation", ",", "operator", "=", "\">=\"", ",", "count", "=", "1", ",", "boolean", "=", "\"and\"", ",", "extra", "=", "None", ")", ":", "if", "relation", ".", "find", "(", "\".\"", ")", ">=", "0", ":", "return", "...
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 :param extra: The extra query :type extra: Builder or callable :type: Builder
[ "Add", "a", "relationship", "count", "condition", "to", "the", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L646-L683
train
225,832
sdispater/orator
orator/orm/builder.py
Builder._add_has_where
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 :param operator: The operator :type operator: str :param count: The count :type count: int :param boolean: The boolean value :type boolean: str :rtype: Builder """ self._merge_model_defined_relation_wheres_to_has_query(has_query, relation) if isinstance(count, basestring) and count.isdigit(): count = QueryExpression(count) return self.where( QueryExpression("(%s)" % has_query.to_sql()), operator, count, boolean )
python
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 :param operator: The operator :type operator: str :param count: The count :type count: int :param boolean: The boolean value :type boolean: str :rtype: Builder """ self._merge_model_defined_relation_wheres_to_has_query(has_query, relation) if isinstance(count, basestring) and count.isdigit(): count = QueryExpression(count) return self.where( QueryExpression("(%s)" % has_query.to_sql()), operator, count, boolean )
[ "def", "_add_has_where", "(", "self", ",", "has_query", ",", "relation", ",", "operator", ",", "count", ",", "boolean", ")", ":", "self", ".", "_merge_model_defined_relation_wheres_to_has_query", "(", "has_query", ",", "relation", ")", "if", "isinstance", "(", "...
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 count :type count: int :param boolean: The boolean value :type boolean: str :rtype: Builder
[ "Add", "the", "has", "condition", "where", "clause", "to", "the", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L804-L832
train
225,833
sdispater/orator
orator/orm/builder.py
Builder._merge_model_defined_relation_wheres_to_has_query
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.relations.Relation """ relation_query = relation.get_base_query() has_query.merge_wheres(relation_query.wheres, relation_query.get_bindings()) self._query.add_binding(has_query.get_query().get_bindings(), "where")
python
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.relations.Relation """ relation_query = relation.get_base_query() has_query.merge_wheres(relation_query.wheres, relation_query.get_bindings()) self._query.add_binding(has_query.get_query().get_bindings(), "where")
[ "def", "_merge_model_defined_relation_wheres_to_has_query", "(", "self", ",", "has_query", ",", "relation", ")", ":", "relation_query", "=", "relation", ".", "get_base_query", "(", ")", "has_query", ".", "merge_wheres", "(", "relation_query", ".", "wheres", ",", "re...
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
[ "Merge", "the", "wheres", "from", "a", "relation", "query", "to", "a", "has", "query", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L834-L848
train
225,834
sdispater/orator
orator/orm/builder.py
Builder.apply_scopes
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 wheres are on the query before running the # scope so that we can properly group the added scope constraints in the # query as their own isolated nested where statement and avoid issues. original_where_count = len(query.wheres) where_counts = [0, original_where_count] for scope in self._scopes.values(): self._apply_scope(scope, builder) # Again, we will keep track of the count each time we add where clauses so that # we will properly isolate each set of scope constraints inside of their own # nested where clause to avoid any conflicts or issues with logical order. where_counts.append(len(query.wheres)) if self._should_nest_wheres_for_scope(query, original_where_count): self._nest_wheres_for_scope(query, Collection(where_counts).unique().all()) return builder
python
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 wheres are on the query before running the # scope so that we can properly group the added scope constraints in the # query as their own isolated nested where statement and avoid issues. original_where_count = len(query.wheres) where_counts = [0, original_where_count] for scope in self._scopes.values(): self._apply_scope(scope, builder) # Again, we will keep track of the count each time we add where clauses so that # we will properly isolate each set of scope constraints inside of their own # nested where clause to avoid any conflicts or issues with logical order. where_counts.append(len(query.wheres)) if self._should_nest_wheres_for_scope(query, original_where_count): self._nest_wheres_for_scope(query, Collection(where_counts).unique().all()) return builder
[ "def", "apply_scopes", "(", "self", ")", ":", "if", "not", "self", ".", "_scopes", ":", "return", "self", "builder", "=", "copy", ".", "copy", "(", "self", ")", "query", "=", "builder", ".", "get_query", "(", ")", "# We will keep track of how many wheres are...
Get the underlying query builder instance with applied global scopes. :type: Builder
[ "Get", "the", "underlying", "query", "builder", "instance", "with", "applied", "global", "scopes", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L953-L984
train
225,835
sdispater/orator
orator/orm/builder.py
Builder._apply_scope
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): scope(builder) elif isinstance(scope, Scope): scope.apply(builder, self.get_model())
python
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): scope(builder) elif isinstance(scope, Scope): scope.apply(builder, self.get_model())
[ "def", "_apply_scope", "(", "self", ",", "scope", ",", "builder", ")", ":", "if", "callable", "(", "scope", ")", ":", "scope", "(", "builder", ")", "elif", "isinstance", "(", "scope", ",", "Scope", ")", ":", "scope", ".", "apply", "(", "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
[ "Apply", "a", "single", "scope", "on", "the", "given", "builder", "instance", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L986-L999
train
225,836
sdispater/orator
orator/orm/builder.py
Builder._nest_wheres_for_scope
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 as nested queries by slicing the groups of wheres into # their own sections. This is to prevent any confusing logic order. wheres = query.wheres query.wheres = [] # We will take the first offset (typically 0) of where clauses and start # slicing out every scope's where clauses into their own nested where # groups for improved isolation of every scope's added constraints. previous_count = where_counts.pop(0) for where_count in where_counts: query.wheres.append( self._slice_where_conditions( wheres, previous_count, where_count - previous_count ) ) previous_count = where_count
python
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 as nested queries by slicing the groups of wheres into # their own sections. This is to prevent any confusing logic order. wheres = query.wheres query.wheres = [] # We will take the first offset (typically 0) of where clauses and start # slicing out every scope's where clauses into their own nested where # groups for improved isolation of every scope's added constraints. previous_count = where_counts.pop(0) for where_count in where_counts: query.wheres.append( self._slice_where_conditions( wheres, previous_count, where_count - previous_count ) ) previous_count = where_count
[ "def", "_nest_wheres_for_scope", "(", "self", ",", "query", ",", "where_counts", ")", ":", "# Here, we totally remove all of the where clauses since we are going to", "# rebuild them as nested queries by slicing the groups of wheres into", "# their own sections. This is to prevent any confus...
Nest where conditions of the builder and each global scope. :type query: QueryBuilder :type where_counts: list
[ "Nest", "where", "conditions", "of", "the", "builder", "and", "each", "global", "scope", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L1012-L1038
train
225,837
sdispater/orator
orator/orm/builder.py
Builder._slice_where_conditions
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.wheres = wheres[offset : (offset + length)] return {"type": "nested", "query": where_group, "boolean": "and"}
python
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.wheres = wheres[offset : (offset + length)] return {"type": "nested", "query": where_group, "boolean": "and"}
[ "def", "_slice_where_conditions", "(", "self", ",", "wheres", ",", "offset", ",", "length", ")", ":", "where_group", "=", "self", ".", "get_query", "(", ")", ".", "for_nested_where", "(", ")", "where_group", ".", "wheres", "=", "wheres", "[", "offset", ":"...
Create a where list with sliced where conditions. :type wheres: list :type offset: int :type length: int :rtype: list
[ "Create", "a", "where", "list", "with", "sliced", "where", "conditions", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L1040-L1053
train
225,838
sdispater/orator
orator/orm/builder.py
Builder.set_model
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_(model.get_table()) return self
python
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_(model.get_table()) return self
[ "def", "set_model", "(", "self", ",", "model", ")", ":", "self", ".", "_model", "=", "model", "self", ".", "_query", ".", "from_", "(", "model", ".", "get_table", "(", ")", ")", "return", "self" ]
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
[ "Set", "a", "model", "instance", "for", "the", "model", "being", "queried", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/builder.py#L1108-L1122
train
225,839
sdispater/orator
orator/query/grammars/sqlite_grammar.py
SQLiteQueryGrammar.compile_insert
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 """ table = self.wrap_table(query.from__) if not isinstance(values, list): values = [values] # If there is only one row to insert, we just use the normal grammar if len(values) == 1: return super(SQLiteQueryGrammar, self).compile_insert(query, values) names = self.columnize(values[0].keys()) columns = [] # SQLite requires us to build the multi-row insert as a listing of select with # unions joining them together. So we'll build out this list of columns and # then join them all together with select unions to complete the queries. for column in values[0].keys(): columns.append("%s AS %s" % (self.get_marker(), self.wrap(column))) columns = [", ".join(columns)] * len(values) return "INSERT INTO %s (%s) SELECT %s" % ( table, names, " UNION ALL SELECT ".join(columns), )
python
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 """ table = self.wrap_table(query.from__) if not isinstance(values, list): values = [values] # If there is only one row to insert, we just use the normal grammar if len(values) == 1: return super(SQLiteQueryGrammar, self).compile_insert(query, values) names = self.columnize(values[0].keys()) columns = [] # SQLite requires us to build the multi-row insert as a listing of select with # unions joining them together. So we'll build out this list of columns and # then join them all together with select unions to complete the queries. for column in values[0].keys(): columns.append("%s AS %s" % (self.get_marker(), self.wrap(column))) columns = [", ".join(columns)] * len(values) return "INSERT INTO %s (%s) SELECT %s" % ( table, names, " UNION ALL SELECT ".join(columns), )
[ "def", "compile_insert", "(", "self", ",", "query", ",", "values", ")", ":", "table", "=", "self", ".", "wrap_table", "(", "query", ".", "from__", ")", "if", "not", "isinstance", "(", "values", ",", "list", ")", ":", "values", "=", "[", "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", "insert", "statement", "into", "SQL" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/sqlite_grammar.py#L26-L64
train
225,840
sdispater/orator
orator/query/grammars/sqlite_grammar.py
SQLiteQueryGrammar.compile_truncate
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 name = %s" % self.get_marker(): [query.from__] } sql["DELETE FROM %s" % self.wrap_table(query.from__)] = [] return sql
python
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 name = %s" % self.get_marker(): [query.from__] } sql["DELETE FROM %s" % self.wrap_table(query.from__)] = [] return sql
[ "def", "compile_truncate", "(", "self", ",", "query", ")", ":", "sql", "=", "{", "\"DELETE FROM sqlite_sequence WHERE name = %s\"", "%", "self", ".", "get_marker", "(", ")", ":", "[", "query", ".", "from__", "]", "}", "sql", "[", "\"DELETE FROM %s\"", "%", "...
Compile a truncate statement into SQL :param query: A QueryBuilder instance :type query: QueryBuilder :return: The compiled truncate statement :rtype: str
[ "Compile", "a", "truncate", "statement", "into", "SQL" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/grammars/sqlite_grammar.py#L66-L83
train
225,841
sdispater/orator
orator/schema/blueprint.py
Blueprint.build
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 """ for statement in self.to_sql(connection, grammar): connection.statement(statement)
python
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 """ for statement in self.to_sql(connection, grammar): connection.statement(statement)
[ "def", "build", "(", "self", ",", "connection", ",", "grammar", ")", ":", "for", "statement", "in", "self", ".", "to_sql", "(", "connection", ",", "grammar", ")", ":", "connection", ".", "statement", "(", "statement", ")" ]
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
[ "Execute", "the", "blueprint", "against", "the", "database", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L19-L30
train
225,842
sdispater/orator
orator/schema/blueprint.py
Blueprint.to_sql
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 :rtype: list """ self._add_implied_commands() statements = [] for command in self._commands: method = "compile_%s" % command.name if hasattr(grammar, method): sql = getattr(grammar, method)(self, command, connection) if sql is not None: if isinstance(sql, list): statements += sql else: statements.append(sql) return statements
python
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 :rtype: list """ self._add_implied_commands() statements = [] for command in self._commands: method = "compile_%s" % command.name if hasattr(grammar, method): sql = getattr(grammar, method)(self, command, connection) if sql is not None: if isinstance(sql, list): statements += sql else: statements.append(sql) return statements
[ "def", "to_sql", "(", "self", ",", "connection", ",", "grammar", ")", ":", "self", ".", "_add_implied_commands", "(", ")", "statements", "=", "[", "]", "for", "command", "in", "self", ".", "_commands", ":", "method", "=", "\"compile_%s\"", "%", "command", ...
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
[ "Get", "the", "raw", "SQL", "statements", "for", "the", "blueprint", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L32-L59
train
225,843
sdispater/orator
orator/schema/blueprint.py
Blueprint._add_implied_commands
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(): self._commands.insert(0, self._create_command("change")) return self._add_fluent_indexes()
python
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(): self._commands.insert(0, self._create_command("change")) return self._add_fluent_indexes()
[ "def", "_add_implied_commands", "(", "self", ")", ":", "if", "len", "(", "self", ".", "get_added_columns", "(", ")", ")", "and", "not", "self", ".", "_creating", "(", ")", ":", "self", ".", "_commands", ".", "insert", "(", "0", ",", "self", ".", "_cr...
Add the commands that are implied by the blueprint.
[ "Add", "the", "commands", "that", "are", "implied", "by", "the", "blueprint", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L61-L71
train
225,844
sdispater/orator
orator/schema/blueprint.py
Blueprint.drop_column
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)
python
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)
[ "def", "drop_column", "(", "self", ",", "*", "columns", ")", ":", "columns", "=", "list", "(", "columns", ")", "return", "self", ".", "_add_command", "(", "\"drop_column\"", ",", "columns", "=", "columns", ")" ]
Indicates that the given columns should be dropped. :param columns: The columns to drop :type columns: tuple :rtype: Fluent
[ "Indicates", "that", "the", "given", "columns", "should", "be", "dropped", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L128-L139
train
225,845
sdispater/orator
orator/schema/blueprint.py
Blueprint.integer
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_column( "integer", column, auto_increment=auto_increment, unsigned=unsigned )
python
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_column( "integer", column, auto_increment=auto_increment, unsigned=unsigned )
[ "def", "integer", "(", "self", ",", "column", ",", "auto_increment", "=", "False", ",", "unsigned", "=", "False", ")", ":", "return", "self", ".", "_add_column", "(", "\"integer\"", ",", "column", ",", "auto_increment", "=", "auto_increment", ",", "unsigned"...
Create a new integer column on the table. :param column: The column :type column: str :type auto_increment: bool :type unsigned: bool :rtype: Fluent
[ "Create", "a", "new", "integer", "column", "on", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L358-L373
train
225,846
sdispater/orator
orator/schema/blueprint.py
Blueprint.small_integer
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 self._add_column( "small_integer", column, auto_increment=auto_increment, unsigned=unsigned )
python
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 self._add_column( "small_integer", column, auto_increment=auto_increment, unsigned=unsigned )
[ "def", "small_integer", "(", "self", ",", "column", ",", "auto_increment", "=", "False", ",", "unsigned", "=", "False", ")", ":", "return", "self", ".", "_add_column", "(", "\"small_integer\"", ",", "column", ",", "auto_increment", "=", "auto_increment", ",", ...
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
[ "Create", "a", "new", "small", "integer", "column", "on", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L426-L441
train
225,847
sdispater/orator
orator/schema/blueprint.py
Blueprint.unsigned_integer
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)
python
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)
[ "def", "unsigned_integer", "(", "self", ",", "column", ",", "auto_increment", "=", "False", ")", ":", "return", "self", ".", "integer", "(", "column", ",", "auto_increment", ",", "True", ")" ]
Create a new unisgned integer column on the table. :param column: The column :type column: str :type auto_increment: bool :rtype: Fluent
[ "Create", "a", "new", "unisgned", "integer", "column", "on", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L443-L454
train
225,848
sdispater/orator
orator/schema/blueprint.py
Blueprint.unsigned_big_integer
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_increment, True)
python
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_increment, True)
[ "def", "unsigned_big_integer", "(", "self", ",", "column", ",", "auto_increment", "=", "False", ")", ":", "return", "self", ".", "big_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
[ "Create", "a", "new", "unsigned", "big", "integer", "column", "on", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L456-L467
train
225,849
sdispater/orator
orator/schema/blueprint.py
Blueprint.float
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=places)
python
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=places)
[ "def", "float", "(", "self", ",", "column", ",", "total", "=", "8", ",", "places", "=", "2", ")", ":", "return", "self", ".", "_add_column", "(", "\"float\"", ",", "column", ",", "total", "=", "total", ",", "places", "=", "places", ")" ]
Create a new float column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent
[ "Create", "a", "new", "float", "column", "on", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L469-L482
train
225,850
sdispater/orator
orator/schema/blueprint.py
Blueprint.double
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=total, places=places)
python
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=total, places=places)
[ "def", "double", "(", "self", ",", "column", ",", "total", "=", "None", ",", "places", "=", "None", ")", ":", "return", "self", ".", "_add_column", "(", "\"double\"", ",", "column", ",", "total", "=", "total", ",", "places", "=", "places", ")" ]
Create a new double column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent
[ "Create", "a", "new", "double", "column", "on", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L484-L497
train
225,851
sdispater/orator
orator/schema/blueprint.py
Blueprint.decimal
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, places=places)
python
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, places=places)
[ "def", "decimal", "(", "self", ",", "column", ",", "total", "=", "8", ",", "places", "=", "2", ")", ":", "return", "self", ".", "_add_column", "(", "\"decimal\"", ",", "column", ",", "total", "=", "total", ",", "places", "=", "places", ")" ]
Create a new decimal column on the table. :param column: The column :type column: str :type total: int :type places: 2 :rtype: Fluent
[ "Create", "a", "new", "decimal", "column", "on", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L499-L512
train
225,852
sdispater/orator
orator/schema/blueprint.py
Blueprint.timestamps
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.timestamp("created_at") self.timestamp("updated_at")
python
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.timestamp("created_at") self.timestamp("updated_at")
[ "def", "timestamps", "(", "self", ",", "use_current", "=", "True", ")", ":", "if", "use_current", ":", "self", ".", "timestamp", "(", "\"created_at\"", ")", ".", "use_current", "(", ")", "self", ".", "timestamp", "(", "\"updated_at\"", ")", ".", "use_curre...
Create creation and update timestamps to the table. :rtype: Fluent
[ "Create", "creation", "and", "update", "timestamps", "to", "the", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L602-L613
train
225,853
sdispater/orator
orator/schema/blueprint.py
Blueprint.morphs
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], index_name)
python
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], index_name)
[ "def", "morphs", "(", "self", ",", "name", ",", "index_name", "=", "None", ")", ":", "self", ".", "unsigned_integer", "(", "\"%s_id\"", "%", "name", ")", "self", ".", "string", "(", "\"%s_type\"", "%", "name", ")", "self", ".", "index", "(", "[", "\"...
Add the proper columns for a polymorphic table. :type name: str :type index_name: str
[ "Add", "the", "proper", "columns", "for", "a", "polymorphic", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L634-L644
train
225,854
sdispater/orator
orator/schema/blueprint.py
Blueprint._drop_index_command
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 :rtype: Fluent """ columns = [] if isinstance(index, list): columns = index index = self._create_index_name(type, columns) return self._index_command(command, columns, index)
python
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 :rtype: Fluent """ columns = [] if isinstance(index, list): columns = index index = self._create_index_name(type, columns) return self._index_command(command, columns, index)
[ "def", "_drop_index_command", "(", "self", ",", "command", ",", "type", ",", "index", ")", ":", "columns", "=", "[", "]", "if", "isinstance", "(", "index", ",", "list", ")", ":", "columns", "=", "index", "index", "=", "self", ".", "_create_index_name", ...
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
[ "Create", "a", "new", "drop", "index", "command", "on", "the", "blueprint", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L646-L668
train
225,855
sdispater/orator
orator/schema/blueprint.py
Blueprint._index_command
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 :rtype: Fluent """ if not isinstance(columns, list): columns = [columns] if not index: index = self._create_index_name(type, columns) return self._add_command(type, index=index, columns=columns)
python
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 :rtype: Fluent """ if not isinstance(columns, list): columns = [columns] if not index: index = self._create_index_name(type, columns) return self._add_command(type, index=index, columns=columns)
[ "def", "_index_command", "(", "self", ",", "type", ",", "columns", ",", "index", ")", ":", "if", "not", "isinstance", "(", "columns", ",", "list", ")", ":", "columns", "=", "[", "columns", "]", "if", "not", "index", ":", "index", "=", "self", ".", ...
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
[ "Add", "a", "new", "index", "command", "to", "the", "blueprint", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L670-L691
train
225,856
sdispater/orator
orator/schema/blueprint.py
Blueprint._remove_column
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
python
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
[ "def", "_remove_column", "(", "self", ",", "name", ")", ":", "self", ".", "_columns", "=", "filter", "(", "lambda", "c", ":", "c", ".", "name", "!=", "name", ",", "self", ".", "_columns", ")", "return", "self" ]
Removes a column from the blueprint. :param name: The column name :type name: str :rtype: Blueprint
[ "Removes", "a", "column", "from", "the", "blueprint", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L727-L738
train
225,857
sdispater/orator
orator/schema/blueprint.py
Blueprint._add_command
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(name, **parameters) self._commands.append(command) return command
python
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(name, **parameters) self._commands.append(command) return command
[ "def", "_add_command", "(", "self", ",", "name", ",", "*", "*", "parameters", ")", ":", "command", "=", "self", ".", "_create_command", "(", "name", ",", "*", "*", "parameters", ")", "self", ".", "_commands", ".", "append", "(", "command", ")", "return...
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
[ "Add", "a", "new", "command", "to", "the", "blueprint", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/blueprint.py#L740-L755
train
225,858
sdispater/orator
orator/dbal/index.py
Index.get_quoted_columns
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 inserted is returned. :param platform: The platform to use for quotation. :type platform: Platform :rtype: list """ columns = [] for column in self._columns.values(): columns.append(column.get_quoted_name(platform)) return columns
python
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 inserted is returned. :param platform: The platform to use for quotation. :type platform: Platform :rtype: list """ columns = [] for column in self._columns.values(): columns.append(column.get_quoted_name(platform)) return columns
[ "def", "get_quoted_columns", "(", "self", ",", "platform", ")", ":", "columns", "=", "[", "]", "for", "column", "in", "self", ".", "_columns", ".", "values", "(", ")", ":", "columns", ".", "append", "(", "column", ".", "get_quoted_name", "(", "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 inserted is returned. :param platform: The platform to use for quotation. :type platform: Platform :rtype: list
[ "Returns", "the", "quoted", "representation", "of", "the", "column", "names", "the", "constraint", "is", "associated", "with", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L65-L84
train
225,859
sdispater/orator
orator/dbal/index.py
Index.spans_columns
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 for i in range(number_of_columns): column = self._trim_quotes(columns[i].lower()) if i >= len(column_names) or column != self._trim_quotes( column_names[i].lower() ): same_columns = False return same_columns
python
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 for i in range(number_of_columns): column = self._trim_quotes(columns[i].lower()) if i >= len(column_names) or column != self._trim_quotes( column_names[i].lower() ): same_columns = False return same_columns
[ "def", "spans_columns", "(", "self", ",", "column_names", ")", ":", "columns", "=", "self", ".", "get_columns", "(", ")", "number_of_columns", "=", "len", "(", "columns", ")", "same_columns", "=", "True", "for", "i", "in", "range", "(", "number_of_columns", ...
Checks if this index exactly spans the given column names in the correct order. :type column_names: list :rtype: bool
[ "Checks", "if", "this", "index", "exactly", "spans", "the", "given", "column", "names", "in", "the", "correct", "order", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L115-L134
train
225,860
sdispater/orator
orator/dbal/index.py
Index.is_fullfilled_by
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. It being larger is an option # but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo) if len(other.get_columns()) != len(self.get_columns()): return False # Check if columns are the same, and even in the same order if not self.spans_columns(other.get_columns()): return False if not self.same_partial_index(other): return False if self.is_simple_index(): # this is a special case: If the current key is neither primary or unique, # any unique or primary key will always have the same effect # for the index and there cannot be any constraint overlaps. # This means a primary or unique index can always fulfill # the requirements of just an index that has no constraints. return True if other.is_primary() != self.is_primary(): return False if other.is_unique() != self.is_unique(): return False return True
python
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. It being larger is an option # but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo) if len(other.get_columns()) != len(self.get_columns()): return False # Check if columns are the same, and even in the same order if not self.spans_columns(other.get_columns()): return False if not self.same_partial_index(other): return False if self.is_simple_index(): # this is a special case: If the current key is neither primary or unique, # any unique or primary key will always have the same effect # for the index and there cannot be any constraint overlaps. # This means a primary or unique index can always fulfill # the requirements of just an index that has no constraints. return True if other.is_primary() != self.is_primary(): return False if other.is_unique() != self.is_unique(): return False return True
[ "def", "is_fullfilled_by", "(", "self", ",", "other", ")", ":", "# allow the other index to be equally large only. It being larger is an option", "# but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)", "if", "len", "(", "other", ".", "get_columns", "...
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
[ "Checks", "if", "the", "other", "index", "already", "fulfills", "all", "the", "indexing", "and", "constraint", "needs", "of", "the", "current", "one", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L136-L172
train
225,861
sdispater/orator
orator/dbal/index.py
Index.same_partial_index
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") and self.get_option("where") == other.get_option("where") ): return True if not self.has_option("where") and not other.has_option("where"): return True return False
python
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") and self.get_option("where") == other.get_option("where") ): return True if not self.has_option("where") and not other.has_option("where"): return True return False
[ "def", "same_partial_index", "(", "self", ",", "other", ")", ":", "if", "(", "self", ".", "has_option", "(", "\"where\"", ")", "and", "other", ".", "has_option", "(", "\"where\"", ")", "and", "self", ".", "get_option", "(", "\"where\"", ")", "==", "other...
Return whether the two indexes have the same partial index :param other: The other index :type other: Index :rtype: bool
[ "Return", "whether", "the", "two", "indexes", "have", "the", "same", "partial", "index" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L174-L193
train
225,862
sdispater/orator
orator/dbal/index.py
Index.overrules
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 elif self.is_simple_index() and other.is_unique(): return False same_columns = self.spans_columns(other.get_columns()) if ( same_columns and (self.is_primary() or self.is_unique()) and self.same_partial_index(other) ): return True return False
python
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 elif self.is_simple_index() and other.is_unique(): return False same_columns = self.spans_columns(other.get_columns()) if ( same_columns and (self.is_primary() or self.is_unique()) and self.same_partial_index(other) ): return True return False
[ "def", "overrules", "(", "self", ",", "other", ")", ":", "if", "other", ".", "is_primary", "(", ")", ":", "return", "False", "elif", "self", ".", "is_simple_index", "(", ")", "and", "other", ".", "is_unique", "(", ")", ":", "return", "False", "same_col...
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
[ "Detects", "if", "the", "other", "index", "is", "a", "non", "-", "unique", "non", "primary", "index", "that", "can", "be", "overwritten", "by", "this", "one", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L195-L218
train
225,863
sdispater/orator
orator/dbal/index.py
Index.remove_flag
def remove_flag(self, flag): """ Removes a flag. :type flag: str """ if self.has_flag(flag): del self._flags[flag.lower()]
python
def remove_flag(self, flag): """ Removes a flag. :type flag: str """ if self.has_flag(flag): del self._flags[flag.lower()]
[ "def", "remove_flag", "(", "self", ",", "flag", ")", ":", "if", "self", ".", "has_flag", "(", "flag", ")", ":", "del", "self", ".", "_flags", "[", "flag", ".", "lower", "(", ")", "]" ]
Removes a flag. :type flag: str
[ "Removes", "a", "flag", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/index.py#L252-L259
train
225,864
sdispater/orator
orator/schema/grammars/mysql_grammar.py
MySQLSchemaGrammar._compile_create_encoding
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.charset or connection.get_config("charset") if charset: sql += " DEFAULT CHARACTER SET %s" % charset collation = blueprint.collation or connection.get_config("collation") if collation: sql += " COLLATE %s" % collation return sql
python
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.charset or connection.get_config("charset") if charset: sql += " DEFAULT CHARACTER SET %s" % charset collation = blueprint.collation or connection.get_config("collation") if collation: sql += " COLLATE %s" % collation return sql
[ "def", "_compile_create_encoding", "(", "self", ",", "sql", ",", "connection", ",", "blueprint", ")", ":", "charset", "=", "blueprint", ".", "charset", "or", "connection", ".", "get_config", "(", "\"charset\"", ")", "if", "charset", ":", "sql", "+=", "\" DEF...
Append the character set specifications to a command. :type sql: str :type connection: orator.connections.Connection :type blueprint: Blueprint :rtype: str
[ "Append", "the", "character", "set", "specifications", "to", "a", "command", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/schema/grammars/mysql_grammar.py#L71-L89
train
225,865
sdispater/orator
orator/commands/seeds/seed_command.py
SeedCommand._get_path
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)
python
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)
[ "def", "_get_path", "(", "self", ",", "name", ")", ":", "path", "=", "self", ".", "option", "(", "\"path\"", ")", "if", "path", "is", "None", ":", "path", "=", "self", ".", "_get_seeders_path", "(", ")", "return", "os", ".", "path", ".", "join", "(...
Get the destination class path. :param name: The name :type name: str :rtype: str
[ "Get", "the", "destination", "class", "path", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/commands/seeds/seed_command.py#L63-L76
train
225,866
sdispater/orator
orator/orm/relations/has_one_or_many.py
HasOneOrMany.update
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._related.uses_timestamps(): attributes[self.get_related_updated_at()] = self._related.fresh_timestamp() return self._query.update(attributes)
python
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._related.uses_timestamps(): attributes[self.get_related_updated_at()] = self._related.fresh_timestamp() return self._query.update(attributes)
[ "def", "update", "(", "self", ",", "_attributes", "=", "None", ",", "*", "*", "attributes", ")", ":", "if", "_attributes", "is", "not", "None", ":", "attributes", ".", "update", "(", "_attributes", ")", "if", "self", ".", "_related", ".", "uses_timestamp...
Perform an update on all the related models. :param attributes: The attributes :type attributes: dict :rtype: int
[ "Perform", "an", "update", "on", "all", "the", "related", "models", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/orm/relations/has_one_or_many.py#L297-L312
train
225,867
sdispater/orator
orator/utils/url.py
URL.get_dialect
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) # check for legacy dialects that # would return a module with 'dialect' as the # actual class if ( hasattr(cls, "dialect") and isinstance(cls.dialect, type) and issubclass(cls.dialect, Dialect) ): return cls.dialect else: return cls
python
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) # check for legacy dialects that # would return a module with 'dialect' as the # actual class if ( hasattr(cls, "dialect") and isinstance(cls.dialect, type) and issubclass(cls.dialect, Dialect) ): return cls.dialect else: return cls
[ "def", "get_dialect", "(", "self", ")", ":", "if", "\"+\"", "not", "in", "self", ".", "drivername", ":", "name", "=", "self", ".", "drivername", "else", ":", "name", "=", "self", ".", "drivername", ".", "replace", "(", "\"+\"", ",", "\".\"", ")", "cl...
Return the SQLAlchemy database dialect class corresponding to this URL's driver name.
[ "Return", "the", "SQLAlchemy", "database", "dialect", "class", "corresponding", "to", "this", "URL", "s", "driver", "name", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/utils/url.py#L122-L142
train
225,868
sdispater/orator
orator/utils/url.py
URL.translate_connect_args
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. Unset or false attributes are omitted from the final dictionary. :param \**kw: Optional, alternate key names for url attributes. :param names: Deprecated. Same purpose as the keyword-based alternate names, but correlates the name to the original positionally. """ translated = {} attribute_names = ["host", "database", "username", "password", "port"] for sname in attribute_names: if names: name = names.pop(0) elif sname in kw: name = kw[sname] else: name = sname if name is not None and getattr(self, sname, False): translated[name] = getattr(self, sname) return translated
python
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. Unset or false attributes are omitted from the final dictionary. :param \**kw: Optional, alternate key names for url attributes. :param names: Deprecated. Same purpose as the keyword-based alternate names, but correlates the name to the original positionally. """ translated = {} attribute_names = ["host", "database", "username", "password", "port"] for sname in attribute_names: if names: name = names.pop(0) elif sname in kw: name = kw[sname] else: name = sname if name is not None and getattr(self, sname, False): translated[name] = getattr(self, sname) return translated
[ "def", "translate_connect_args", "(", "self", ",", "names", "=", "[", "]", ",", "*", "*", "kw", ")", ":", "translated", "=", "{", "}", "attribute_names", "=", "[", "\"host\"", ",", "\"database\"", ",", "\"username\"", ",", "\"password\"", ",", "\"port\"", ...
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 dictionary. :param \**kw: Optional, alternate key names for url attributes. :param names: Deprecated. Same purpose as the keyword-based alternate names, but correlates the name to the original positionally.
[ "Translate", "url", "attributes", "into", "a", "dictionary", "of", "connection", "arguments", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/utils/url.py#L144-L169
train
225,869
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_check_declaration_sql
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 code portion needed to set a CHECK constraint. :rtype: str """ constraints = [] for field, def_ in definition.items(): if isinstance(def_, basestring): constraints.append("CHECK (%s)" % def_) else: if "min" in def_: constraints.append("CHECK (%s >= %s)" % (field, def_["min"])) if "max" in def_: constraints.append("CHECK (%s <= %s)" % (field, def_["max"])) return ", ".join(constraints)
python
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 code portion needed to set a CHECK constraint. :rtype: str """ constraints = [] for field, def_ in definition.items(): if isinstance(def_, basestring): constraints.append("CHECK (%s)" % def_) else: if "min" in def_: constraints.append("CHECK (%s >= %s)" % (field, def_["min"])) if "max" in def_: constraints.append("CHECK (%s <= %s)" % (field, def_["max"])) return ", ".join(constraints)
[ "def", "get_check_declaration_sql", "(", "self", ",", "definition", ")", ":", "constraints", "=", "[", "]", "for", "field", ",", "def_", "in", "definition", ".", "items", "(", ")", ":", "if", "isinstance", "(", "def_", ",", "basestring", ")", ":", "const...
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
[ "Obtains", "DBMS", "specific", "SQL", "code", "portion", "needed", "to", "set", "a", "CHECK", "constraint", "declaration", "to", "be", "used", "in", "statements", "like", "CREATE", "TABLE", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L71-L93
train
225,870
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_unique_constraint_declaration_sql
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 index: The index definition :type index: Index :return: DBMS specific SQL code portion needed to set a constraint. :rtype: str """ columns = index.get_quoted_columns(self) name = Identifier(name) if not columns: raise DBALException('Incomplete definition. "columns" required.') return "CONSTRAINT %s UNIQUE (%s)%s" % ( name.get_quoted_name(self), self.get_index_field_declaration_list_sql(columns), self.get_partial_index_sql(index), )
python
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 index: The index definition :type index: Index :return: DBMS specific SQL code portion needed to set a constraint. :rtype: str """ columns = index.get_quoted_columns(self) name = Identifier(name) if not columns: raise DBALException('Incomplete definition. "columns" required.') return "CONSTRAINT %s UNIQUE (%s)%s" % ( name.get_quoted_name(self), self.get_index_field_declaration_list_sql(columns), self.get_partial_index_sql(index), )
[ "def", "get_unique_constraint_declaration_sql", "(", "self", ",", "name", ",", "index", ")", ":", "columns", "=", "index", ".", "get_quoted_columns", "(", "self", ")", "name", "=", "Identifier", "(", "name", ")", "if", "not", "columns", ":", "raise", "DBALEx...
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 SQL code portion needed to set a constraint. :rtype: str
[ "Obtains", "DBMS", "specific", "SQL", "code", "portion", "needed", "to", "set", "a", "unique", "constraint", "declaration", "to", "be", "used", "in", "statements", "like", "CREATE", "TABLE", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L95-L119
train
225,871
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_foreign_key_declaration_sql
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: ForeignKeyConstraint :rtype: str """ sql = self.get_foreign_key_base_declaration_sql(foreign_key) sql += self.get_advanced_foreign_key_options_sql(foreign_key) return sql
python
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: ForeignKeyConstraint :rtype: str """ sql = self.get_foreign_key_base_declaration_sql(foreign_key) sql += self.get_advanced_foreign_key_options_sql(foreign_key) return sql
[ "def", "get_foreign_key_declaration_sql", "(", "self", ",", "foreign_key", ")", ":", "sql", "=", "self", ".", "get_foreign_key_base_declaration_sql", "(", "foreign_key", ")", "sql", "+=", "self", ".", "get_advanced_foreign_key_options_sql", "(", "foreign_key", ")", "r...
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
[ "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", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L148-L161
train
225,872
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_advanced_foreign_key_options_sql
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 """ query = "" if self.supports_foreign_key_on_update() and foreign_key.has_option( "on_update" ): query += " ON UPDATE %s" % self.get_foreign_key_referential_action_sql( foreign_key.get_option("on_update") ) if foreign_key.has_option("on_delete"): query += " ON DELETE %s" % self.get_foreign_key_referential_action_sql( foreign_key.get_option("on_delete") ) return query
python
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 """ query = "" if self.supports_foreign_key_on_update() and foreign_key.has_option( "on_update" ): query += " ON UPDATE %s" % self.get_foreign_key_referential_action_sql( foreign_key.get_option("on_update") ) if foreign_key.has_option("on_delete"): query += " ON DELETE %s" % self.get_foreign_key_referential_action_sql( foreign_key.get_option("on_delete") ) return query
[ "def", "get_advanced_foreign_key_options_sql", "(", "self", ",", "foreign_key", ")", ":", "query", "=", "\"\"", "if", "self", ".", "supports_foreign_key_on_update", "(", ")", "and", "foreign_key", ".", "has_option", "(", "\"on_update\"", ")", ":", "query", "+=", ...
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", "FOREIGN", "KEY", "query", "section", "dealing", "with", "non", "-", "standard", "options", "as", "MATCH", "INITIALLY", "DEFERRED", "ON", "UPDATE", "..." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L163-L186
train
225,873
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_foreign_key_referential_action_sql
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 [ "CASCADE", "SET NULL", "NO ACTION", "RESTRICT", "SET DEFAULT", ]: raise DBALException("Invalid foreign key action: %s" % action) return action
python
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 [ "CASCADE", "SET NULL", "NO ACTION", "RESTRICT", "SET DEFAULT", ]: raise DBALException("Invalid foreign key action: %s" % action) return action
[ "def", "get_foreign_key_referential_action_sql", "(", "self", ",", "action", ")", ":", "action", "=", "action", ".", "upper", "(", ")", "if", "action", "not", "in", "[", "\"CASCADE\"", ",", "\"SET NULL\"", ",", "\"NO ACTION\"", ",", "\"RESTRICT\"", ",", "\"SET...
Returns the given referential action in uppercase if valid, otherwise throws an exception. :param action: The action :type action: str :rtype: str
[ "Returns", "the", "given", "referential", "action", "in", "uppercase", "if", "valid", "otherwise", "throws", "an", "exception", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L188-L207
train
225,874
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_foreign_key_base_declaration_sql
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: ForeignKeyConstraint :rtype: str """ sql = "" if foreign_key.get_name(): sql += "CONSTRAINT %s " % foreign_key.get_quoted_name(self) sql += "FOREIGN KEY (" if not foreign_key.get_local_columns(): raise DBALException('Incomplete definition. "local" required.') if not foreign_key.get_foreign_columns(): raise DBALException('Incomplete definition. "foreign" required.') if not foreign_key.get_foreign_table_name(): raise DBALException('Incomplete definition. "foreign_table" required.') sql += "%s) REFERENCES %s (%s)" % ( ", ".join(foreign_key.get_quoted_local_columns(self)), foreign_key.get_quoted_foreign_table_name(self), ", ".join(foreign_key.get_quoted_foreign_columns(self)), ) return sql
python
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: ForeignKeyConstraint :rtype: str """ sql = "" if foreign_key.get_name(): sql += "CONSTRAINT %s " % foreign_key.get_quoted_name(self) sql += "FOREIGN KEY (" if not foreign_key.get_local_columns(): raise DBALException('Incomplete definition. "local" required.') if not foreign_key.get_foreign_columns(): raise DBALException('Incomplete definition. "foreign" required.') if not foreign_key.get_foreign_table_name(): raise DBALException('Incomplete definition. "foreign_table" required.') sql += "%s) REFERENCES %s (%s)" % ( ", ".join(foreign_key.get_quoted_local_columns(self)), foreign_key.get_quoted_foreign_table_name(self), ", ".join(foreign_key.get_quoted_foreign_columns(self)), ) return sql
[ "def", "get_foreign_key_base_declaration_sql", "(", "self", ",", "foreign_key", ")", ":", "sql", "=", "\"\"", "if", "foreign_key", ".", "get_name", "(", ")", ":", "sql", "+=", "\"CONSTRAINT %s \"", "%", "foreign_key", ".", "get_quoted_name", "(", "self", ")", ...
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
[ "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", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L209-L240
train
225,875
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_column_declaration_list_sql
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)
python
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)
[ "def", "get_column_declaration_list_sql", "(", "self", ",", "fields", ")", ":", "query_fields", "=", "[", "]", "for", "name", ",", "field", "in", "fields", ".", "items", "(", ")", ":", "query_fields", ".", "append", "(", "self", ".", "get_column_declaration_...
Gets declaration of a number of fields in bulk.
[ "Gets", "declaration", "of", "a", "number", "of", "fields", "in", "bulk", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L256-L265
train
225,876
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_create_index_sql
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, Table): table = table.get_quoted_name(self) name = index.get_quoted_name(self) columns = index.get_quoted_columns(self) if not columns: raise DBALException('Incomplete definition. "columns" required.') if index.is_primary(): return self.get_create_primary_key_sql(index, table) query = "CREATE %sINDEX %s ON %s" % ( self.get_create_index_sql_flags(index), name, table, ) query += " (%s)%s" % ( self.get_index_field_declaration_list_sql(columns), self.get_partial_index_sql(index), ) return query
python
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, Table): table = table.get_quoted_name(self) name = index.get_quoted_name(self) columns = index.get_quoted_columns(self) if not columns: raise DBALException('Incomplete definition. "columns" required.') if index.is_primary(): return self.get_create_primary_key_sql(index, table) query = "CREATE %sINDEX %s ON %s" % ( self.get_create_index_sql_flags(index), name, table, ) query += " (%s)%s" % ( self.get_index_field_declaration_list_sql(columns), self.get_partial_index_sql(index), ) return query
[ "def", "get_create_index_sql", "(", "self", ",", "index", ",", "table", ")", ":", "if", "isinstance", "(", "table", ",", "Table", ")", ":", "table", "=", "table", ".", "get_quoted_name", "(", "self", ")", "name", "=", "index", ".", "get_quoted_name", "("...
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
[ "Returns", "the", "SQL", "to", "create", "an", "index", "on", "a", "table", "on", "this", "platform", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L418-L452
train
225,877
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_create_primary_key_sql
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 %s ADD PRIMARY KEY (%s)" % ( table, self.get_index_field_declaration_list_sql(index.get_quoted_columns(self)), )
python
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 %s ADD PRIMARY KEY (%s)" % ( table, self.get_index_field_declaration_list_sql(index.get_quoted_columns(self)), )
[ "def", "get_create_primary_key_sql", "(", "self", ",", "index", ",", "table", ")", ":", "return", "\"ALTER TABLE %s ADD PRIMARY KEY (%s)\"", "%", "(", "table", ",", "self", ".", "get_index_field_declaration_list_sql", "(", "index", ".", "get_quoted_columns", "(", "sel...
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
[ "Returns", "the", "SQL", "to", "create", "an", "unnamed", "primary", "key", "constraint", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L482-L497
train
225,878
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_create_foreign_key_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, self.get_foreign_key_declaration_sql(foreign_key), ) return query
python
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, self.get_foreign_key_declaration_sql(foreign_key), ) return query
[ "def", "get_create_foreign_key_sql", "(", "self", ",", "foreign_key", ",", "table", ")", ":", "if", "isinstance", "(", "table", ",", "Table", ")", ":", "table", "=", "table", ".", "get_quoted_name", "(", "self", ")", "query", "=", "\"ALTER TABLE %s ADD %s\"", ...
Returns the SQL to create a new foreign key. :rtype: sql
[ "Returns", "the", "SQL", "to", "create", "a", "new", "foreign", "key", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L499-L513
train
225,879
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_drop_table_sql
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 %s" % table
python
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 %s" % table
[ "def", "get_drop_table_sql", "(", "self", ",", "table", ")", ":", "if", "isinstance", "(", "table", ",", "Table", ")", ":", "table", "=", "table", ".", "get_quoted_name", "(", "self", ")", "return", "\"DROP TABLE %s\"", "%", "table" ]
Returns the SQL snippet to drop an existing table. :param table: The table :type table: Table or str :rtype: str
[ "Returns", "the", "SQL", "snippet", "to", "drop", "an", "existing", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L515-L527
train
225,880
sdispater/orator
orator/dbal/platforms/platform.py
Platform.get_drop_index_sql
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, Index): index = index.get_quoted_name(self) return "DROP INDEX %s" % index
python
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, Index): index = index.get_quoted_name(self) return "DROP INDEX %s" % index
[ "def", "get_drop_index_sql", "(", "self", ",", "index", ",", "table", "=", "None", ")", ":", "if", "isinstance", "(", "index", ",", "Index", ")", ":", "index", "=", "index", ".", "get_quoted_name", "(", "self", ")", "return", "\"DROP INDEX %s\"", "%", "i...
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
[ "Returns", "the", "SQL", "to", "drop", "an", "index", "from", "a", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L529-L544
train
225,881
sdispater/orator
orator/dbal/platforms/platform.py
Platform._get_create_table_sql
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 options :type options: dict :rtype: str """ options = options or {} column_list_sql = self.get_column_declaration_list_sql(columns) if options.get("unique_constraints"): for name, definition in options["unique_constraints"].items(): column_list_sql += ", %s" % self.get_unique_constraint_declaration_sql( name, definition ) if options.get("primary"): column_list_sql += ", PRIMARY KEY(%s)" % ", ".join(options["primary"]) if options.get("indexes"): for index, definition in options["indexes"]: column_list_sql += ", %s" % self.get_index_declaration_sql( index, definition ) query = "CREATE TABLE %s (%s" % (table_name, column_list_sql) check = self.get_check_declaration_sql(columns) if check: query += ", %s" % check query += ")" sql = [query] if options.get("foreign_keys"): for definition in options["foreign_keys"]: sql.append(self.get_create_foreign_key_sql(definition, table_name)) return sql
python
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 options :type options: dict :rtype: str """ options = options or {} column_list_sql = self.get_column_declaration_list_sql(columns) if options.get("unique_constraints"): for name, definition in options["unique_constraints"].items(): column_list_sql += ", %s" % self.get_unique_constraint_declaration_sql( name, definition ) if options.get("primary"): column_list_sql += ", PRIMARY KEY(%s)" % ", ".join(options["primary"]) if options.get("indexes"): for index, definition in options["indexes"]: column_list_sql += ", %s" % self.get_index_declaration_sql( index, definition ) query = "CREATE TABLE %s (%s" % (table_name, column_list_sql) check = self.get_check_declaration_sql(columns) if check: query += ", %s" % check query += ")" sql = [query] if options.get("foreign_keys"): for definition in options["foreign_keys"]: sql.append(self.get_create_foreign_key_sql(definition, table_name)) return sql
[ "def", "_get_create_table_sql", "(", "self", ",", "table_name", ",", "columns", ",", "options", "=", "None", ")", ":", "options", "=", "options", "or", "{", "}", "column_list_sql", "=", "self", ".", "get_column_declaration_list_sql", "(", "columns", ")", "if",...
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
[ "Returns", "the", "SQL", "used", "to", "create", "a", "table", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L605-L653
train
225,882
sdispater/orator
orator/dbal/platforms/platform.py
Platform.quote_identifier
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 to be quoted. :type string: str :return: The quoted identifier string. :rtype: str """ if "." in string: parts = list(map(self.quote_single_identifier, string.split("."))) return ".".join(parts) return self.quote_single_identifier(string)
python
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 to be quoted. :type string: str :return: The quoted identifier string. :rtype: str """ if "." in string: parts = list(map(self.quote_single_identifier, string.split("."))) return ".".join(parts) return self.quote_single_identifier(string)
[ "def", "quote_identifier", "(", "self", ",", "string", ")", ":", "if", "\".\"", "in", "string", ":", "parts", "=", "list", "(", "map", "(", "self", ".", "quote_single_identifier", ",", "string", ".", "split", "(", "\".\"", ")", ")", ")", "return", "\"....
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: The quoted identifier string. :rtype: str
[ "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", ...
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/platforms/platform.py#L655-L672
train
225,883
sdispater/orator
orator/connectors/connector.py
Connector._detect_database_platform
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 = self._get_database_platform_version() if version is not None: self._platform = self._create_database_platform_for_version(version) else: self._platform = self.get_dbal_platform()
python
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 = self._get_database_platform_version() if version is not None: self._platform = self._create_database_platform_for_version(version) else: self._platform = self.get_dbal_platform()
[ "def", "_detect_database_platform", "(", "self", ")", ":", "version", "=", "self", ".", "_get_database_platform_version", "(", ")", "if", "version", "is", "not", "None", ":", "self", ".", "_platform", "=", "self", ".", "_create_database_platform_for_version", "(",...
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.
[ "Detects", "and", "sets", "the", "database", "platform", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/connectors/connector.py#L65-L78
train
225,884
sdispater/orator
orator/pagination/paginator.py
Paginator._check_for_more_pages
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]
python
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]
[ "def", "_check_for_more_pages", "(", "self", ")", ":", "self", ".", "_has_more", "=", "len", "(", "self", ".", "_items", ")", ">", "self", ".", "per_page", "self", ".", "_items", "=", "self", ".", "_items", "[", "0", ":", "self", ".", "per_page", "]"...
Check for more pages. The last item will be sliced off.
[ "Check", "for", "more", "pages", ".", "The", "last", "item", "will", "be", "sliced", "off", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/pagination/paginator.py#L55-L61
train
225,885
sdispater/orator
orator/dbal/comparator.py
Comparator.diff_index
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 :rtype: bool """ if index1.is_fullfilled_by(index2) and index2.is_fullfilled_by(index1): return False return True
python
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 :rtype: bool """ if index1.is_fullfilled_by(index2) and index2.is_fullfilled_by(index1): return False return True
[ "def", "diff_index", "(", "self", ",", "index1", ",", "index2", ")", ":", "if", "index1", ".", "is_fullfilled_by", "(", "index2", ")", "and", "index2", ".", "is_fullfilled_by", "(", "index1", ")", ":", "return", "False", "return", "True" ]
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
[ "Finds", "the", "difference", "between", "the", "indexes", "index1", "and", "index2", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/dbal/comparator.py#L285-L300
train
225,886
sdispater/orator
orator/seeds/seeder.py
Seeder.call
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__)
python
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__)
[ "def", "call", "(", "self", ",", "klass", ")", ":", "self", ".", "_resolve", "(", "klass", ")", ".", "run", "(", ")", "if", "self", ".", "_command", ":", "self", ".", "_command", ".", "line", "(", "\"<info>Seeded:</info> <fg=cyan>%s</>\"", "%", "klass", ...
Seed the given connection from the given class. :param klass: The Seeder class :type klass: class
[ "Seed", "the", "given", "connection", "from", "the", "given", "class", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/seeds/seeder.py#L25-L35
train
225,887
sdispater/orator
orator/seeds/seeder.py
Seeder._resolve
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._command.resolver instance = klass() instance.set_connection_resolver(resolver) if self._command: instance.set_command(self._command) return instance
python
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._command.resolver instance = klass() instance.set_connection_resolver(resolver) if self._command: instance.set_command(self._command) return instance
[ "def", "_resolve", "(", "self", ",", "klass", ")", ":", "resolver", "=", "None", "if", "self", ".", "_resolver", ":", "resolver", "=", "self", ".", "_resolver", "elif", "self", ".", "_command", ":", "resolver", "=", "self", ".", "_command", ".", "resol...
Resolve an instance of the given seeder klass. :param klass: The Seeder class :type klass: class
[ "Resolve", "an", "instance", "of", "the", "given", "seeder", "klass", "." ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/seeds/seeder.py#L37-L57
train
225,888
sdispater/orator
orator/query/builder.py
QueryBuilder.select
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.columns = list(columns) return self
python
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.columns = list(columns) return self
[ "def", "select", "(", "self", ",", "*", "columns", ")", ":", "if", "not", "columns", ":", "columns", "=", "[", "\"*\"", "]", "self", ".", "columns", "=", "list", "(", "columns", ")", "return", "self" ]
Set the columns to be selected :param columns: The columns to be selected :type columns: tuple :return: The current QueryBuilder instance :rtype: QueryBuilder
[ "Set", "the", "columns", "to", "be", "selected" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L90-L105
train
225,889
sdispater/orator
orator/query/builder.py
QueryBuilder.select_raw
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 instance :rtype: QueryBuilder """ self.add_select(QueryExpression(expression)) if bindings: self.add_binding(bindings, "select") return self
python
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 instance :rtype: QueryBuilder """ self.add_select(QueryExpression(expression)) if bindings: self.add_binding(bindings, "select") return self
[ "def", "select_raw", "(", "self", ",", "expression", ",", "bindings", "=", "None", ")", ":", "self", ".", "add_select", "(", "QueryExpression", "(", "expression", ")", ")", "if", "bindings", ":", "self", ".", "add_binding", "(", "bindings", ",", "\"select\...
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
[ "Add", "a", "new", "raw", "select", "expression", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L107-L125
train
225,890
sdispater/orator
orator/query/builder.py
QueryBuilder.select_sub
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 """ if isinstance(query, QueryBuilder): bindings = query.get_bindings() query = query.to_sql() elif isinstance(query, basestring): bindings = [] else: raise ArgumentError("Invalid subselect") return self.select_raw( "(%s) AS %s" % (query, self._grammar.wrap(as_)), bindings )
python
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 """ if isinstance(query, QueryBuilder): bindings = query.get_bindings() query = query.to_sql() elif isinstance(query, basestring): bindings = [] else: raise ArgumentError("Invalid subselect") return self.select_raw( "(%s) AS %s" % (query, self._grammar.wrap(as_)), bindings )
[ "def", "select_sub", "(", "self", ",", "query", ",", "as_", ")", ":", "if", "isinstance", "(", "query", ",", "QueryBuilder", ")", ":", "bindings", "=", "query", ".", "get_bindings", "(", ")", "query", "=", "query", ".", "to_sql", "(", ")", "elif", "i...
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", "subselect", "expression", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L127-L151
train
225,891
sdispater/orator
orator/query/builder.py
QueryBuilder.add_select
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 += list(column) return self
python
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 += list(column) return self
[ "def", "add_select", "(", "self", ",", "*", "column", ")", ":", "if", "not", "column", ":", "column", "=", "[", "]", "self", ".", "columns", "+=", "list", "(", "column", ")", "return", "self" ]
Add a new select column to query :param column: The column to add :type column: str :return: The current QueryBuilder instance :rtype: QueryBuilder
[ "Add", "a", "new", "select", "column", "to", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L153-L168
train
225,892
sdispater/orator
orator/query/builder.py
QueryBuilder.left_join_where
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 :param operator: The operator of the join condition :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder """ return self.join_where(table, one, operator, two, "left")
python
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 :param operator: The operator of the join condition :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder """ return self.join_where(table, one, operator, two, "left")
[ "def", "left_join_where", "(", "self", ",", "table", ",", "one", ",", "operator", ",", "two", ")", ":", "return", "self", ".", "join_where", "(", "table", ",", "one", ",", "operator", ",", "two", ",", "\"left\"", ")" ]
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 :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder
[ "Add", "a", "left", "join", "where", "clause", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L280-L299
train
225,893
sdispater/orator
orator/query/builder.py
QueryBuilder.right_join
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 :param operator: The operator of the join condition :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder """ if isinstance(table, JoinClause): table.type = "right" return self.join(table, one, operator, two, "right")
python
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 :param operator: The operator of the join condition :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder """ if isinstance(table, JoinClause): table.type = "right" return self.join(table, one, operator, two, "right")
[ "def", "right_join", "(", "self", ",", "table", ",", "one", "=", "None", ",", "operator", "=", "None", ",", "two", "=", "None", ")", ":", "if", "isinstance", "(", "table", ",", "JoinClause", ")", ":", "table", ".", "type", "=", "\"right\"", "return",...
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: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder
[ "Add", "a", "right", "join", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L301-L323
train
225,894
sdispater/orator
orator/query/builder.py
QueryBuilder.right_join_where
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: str :param operator: The operator of the join condition :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder """ return self.join_where(table, one, operator, two, "right")
python
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: str :param operator: The operator of the join condition :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder """ return self.join_where(table, one, operator, two, "right")
[ "def", "right_join_where", "(", "self", ",", "table", ",", "one", ",", "operator", ",", "two", ")", ":", "return", "self", ".", "join_where", "(", "table", ",", "one", ",", "operator", ",", "two", ",", "\"right\"", ")" ]
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 :type operator: str :param two: The second column of the join condition :type two: str :return: The current QueryBuilder instance :rtype: QueryBuilder
[ "Add", "a", "right", "join", "where", "clause", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L325-L344
train
225,895
sdispater/orator
orator/query/builder.py
QueryBuilder.group_by
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(column) return self
python
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(column) return self
[ "def", "group_by", "(", "self", ",", "*", "columns", ")", ":", "for", "column", "in", "columns", ":", "self", ".", "groups", ".", "append", "(", "column", ")", "return", "self" ]
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
[ "Add", "a", "group", "by", "clause", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L694-L707
train
225,896
sdispater/orator
orator/query/builder.py
QueryBuilder.having_raw
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 :return: The current QueryBuilder instance :rtype: QueryBuilder """ type = "raw" self.havings.append({"type": type, "sql": sql, "boolean": boolean}) self.add_binding(bindings, "having") return self
python
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 :return: The current QueryBuilder instance :rtype: QueryBuilder """ type = "raw" self.havings.append({"type": type, "sql": sql, "boolean": boolean}) self.add_binding(bindings, "having") return self
[ "def", "having_raw", "(", "self", ",", "sql", ",", "bindings", "=", "None", ",", "boolean", "=", "\"and\"", ")", ":", "type", "=", "\"raw\"", "self", ".", "havings", ".", "append", "(", "{", "\"type\"", ":", "type", ",", "\"sql\"", ":", "sql", ",", ...
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: QueryBuilder
[ "Add", "a", "raw", "having", "clause", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L763-L785
train
225,897
sdispater/orator
orator/query/builder.py
QueryBuilder.order_by
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 :rtype: QueryBuilder """ if self.unions: prop = "union_orders" else: prop = "orders" if direction.lower() == "asc": direction = "asc" else: direction = "desc" getattr(self, prop).append({"column": column, "direction": direction}) return self
python
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 :rtype: QueryBuilder """ if self.unions: prop = "union_orders" else: prop = "orders" if direction.lower() == "asc": direction = "asc" else: direction = "desc" getattr(self, prop).append({"column": column, "direction": direction}) return self
[ "def", "order_by", "(", "self", ",", "column", ",", "direction", "=", "\"asc\"", ")", ":", "if", "self", ".", "unions", ":", "prop", "=", "\"union_orders\"", "else", ":", "prop", "=", "\"orders\"", "if", "direction", ".", "lower", "(", ")", "==", "\"as...
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
[ "Add", "a", "order", "by", "clause", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L802-L827
train
225,898
sdispater/orator
orator/query/builder.py
QueryBuilder.order_by_raw
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 """ if bindings is None: bindings = [] type = "raw" self.orders.append({"type": type, "sql": sql}) self.add_binding(bindings, "order") return self
python
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 """ if bindings is None: bindings = [] type = "raw" self.orders.append({"type": type, "sql": sql}) self.add_binding(bindings, "order") return self
[ "def", "order_by_raw", "(", "self", ",", "sql", ",", "bindings", "=", "None", ")", ":", "if", "bindings", "is", "None", ":", "bindings", "=", "[", "]", "type", "=", "\"raw\"", "self", ".", "orders", ".", "append", "(", "{", "\"type\"", ":", "type", ...
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
[ "Add", "a", "raw", "order", "by", "clause", "to", "the", "query" ]
bd90bf198ee897751848f9a92e49d18e60a74136
https://github.com/sdispater/orator/blob/bd90bf198ee897751848f9a92e49d18e60a74136/orator/query/builder.py#L855-L877
train
225,899