idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
36,900
def _set_renamed_columns ( self , table_diff , command , column ) : new_column = Column ( command . to , column . get_type ( ) , column . to_dict ( ) ) table_diff . renamed_columns = { command . from_ : new_column } return table_diff
Set the renamed columns on the table diff .
36,901
def _get_command_by_name ( self , blueprint , name ) : commands = self . _get_commands_by_name ( blueprint , name ) if len ( commands ) : return commands [ 0 ]
Get the primary key command it it exists .
36,902
def _get_commands_by_name ( self , blueprint , name ) : return list ( filter ( lambda value : value . name == name , blueprint . get_commands ( ) ) )
Get all of the commands with a given name .
36,903
def prefix_list ( self , prefix , values ) : return list ( map ( lambda value : prefix + " " + value , values ) )
Add a prefix to a list of values .
36,904
def _get_default_value ( self , value ) : if isinstance ( value , QueryExpression ) : return value if isinstance ( value , bool ) : return "'%s'" % int ( value ) return "'%s'" % value
Format a value so that it can be used in default clauses .
36,905
def _get_changed_diff ( self , blueprint , schema ) : table = schema . list_table_details ( self . get_table_prefix ( ) + blueprint . get_table ( ) ) return Comparator ( ) . diff_table ( table , self . _get_table_with_column_changes ( blueprint , table ) )
Get the table diffrence for the given changes .
36,906
def _get_table_with_column_changes ( self , blueprint , table ) : table = table . clone ( ) for fluent in blueprint . get_changed_columns ( ) : column = self . _get_column_for_change ( table , fluent ) for key , value in fluent . get_attributes ( ) . items ( ) : option = self . _map_fluent_option ( key ) if option is not None : method = "set_%s" % option if hasattr ( column , method ) : getattr ( column , method ) ( self . _map_fluent_value ( option , value ) ) return table
Get a copy of the given table after making the column changes .
36,907
def _get_column_for_change ( self , table , fluent ) : return table . change_column ( fluent . name , self . _get_column_change_options ( fluent ) ) . get_column ( fluent . name )
Get the column instance for a column change .
36,908
def _get_delete_query ( self ) : foreign = self . get_attribute ( self . __foreign_key ) query = self . new_query ( ) . where ( self . __foreign_key , foreign ) return query . where ( self . __other_key , self . get_attribute ( self . __other_key ) )
Get the query builder for a delete operation on the pivot .
36,909
def set_pivot_keys ( self , foreign_key , other_key ) : self . __foreign_key = foreign_key self . __other_key = other_key return self
Set the key names for the pivot model instance
36,910
def create ( self , ** attributes ) : results = self . make ( ** attributes ) if self . _amount == 1 : if self . _resolver : results . set_connection_resolver ( self . _resolver ) results . save ( ) else : if self . _resolver : results . each ( lambda r : r . set_connection_resolver ( self . _resolver ) ) for result in results : result . save ( ) return results
Create a collection of models and persist them to the database .
36,911
def make ( self , ** attributes ) : if self . _amount == 1 : return self . _make_instance ( ** attributes ) else : results = [ ] for _ in range ( self . _amount ) : results . append ( self . _make_instance ( ** attributes ) ) return Collection ( results )
Create a collection of models .
36,912
def _make_instance ( self , ** attributes ) : definition = self . _definitions [ self . _klass ] [ self . _name ] ( self . _faker ) definition . update ( attributes ) instance = self . _klass ( ) instance . force_fill ( ** definition ) return instance
Make an instance of the model with the given attributes .
36,913
def run ( wrapped ) : @ wraps ( wrapped ) def _run ( self , query , bindings = None , * args , ** kwargs ) : self . _reconnect_if_missing_connection ( ) start = time . time ( ) try : result = wrapped ( self , query , bindings , * args , ** kwargs ) except Exception as e : result = self . _try_again_if_caused_by_lost_connection ( e , query , bindings , wrapped ) t = self . _get_elapsed_time ( start ) self . log_query ( query , bindings , t ) return result return _run
Special decorator encapsulating query method .
36,914
def where_pivot ( self , column , operator = None , value = None , boolean = "and" ) : self . _pivot_wheres . append ( [ column , operator , value , boolean ] ) return self . _query . where ( "%s.%s" % ( self . _table , column ) , operator , value , boolean )
Set a where clause for a pivot table column .
36,915
def or_where_pivot ( self , column , operator = None , value = None ) : return self . where_pivot ( column , operator , value , "or" )
Set an or where clause for a pivot table column .
36,916
def first ( self , columns = None ) : self . _query . take ( 1 ) results = self . get ( columns ) if len ( results ) > 0 : return results . first ( ) return
Execute the query and get the first result .
36,917
def first_or_fail ( self , columns = None ) : model = self . first ( columns ) if model is not None : return model raise ModelNotFound ( self . _parent . __class__ )
Execute the query and get the first result or raise an exception .
36,918
def _hydrate_pivot_relation ( self , models ) : for model in models : pivot = self . new_existing_pivot ( self . _clean_pivot_attributes ( model ) ) model . set_relation ( "pivot" , pivot )
Hydrate the pivot table relationship on the models .
36,919
def touch ( self ) : key = self . get_related ( ) . get_key_name ( ) columns = self . get_related_fresh_update ( ) ids = self . get_related_ids ( ) if len ( ids ) > 0 : self . get_related ( ) . new_query ( ) . where_in ( key , ids ) . update ( columns )
Touch all of the related models of the relationship .
36,920
def get_related_ids ( self ) : related = self . get_related ( ) full_key = related . get_qualified_key_name ( ) return self . get_query ( ) . select ( full_key ) . lists ( related . get_key_name ( ) )
Get all of the IDs for the related models .
36,921
def save_many ( self , models , joinings = None ) : if joinings is None : joinings = { } for key , model in enumerate ( models ) : self . save ( model , joinings . get ( key ) , False ) self . touch_if_touching ( ) return models
Save a list of new models and attach them to the parent model
36,922
def first_or_create ( self , _attributes = None , _joining = None , _touch = True , ** attributes ) : if _attributes is not None : attributes . update ( _attributes ) instance = self . _query . where ( attributes ) . first ( ) if instance is None : instance = self . create ( attributes , _joining or { } , _touch ) return instance
Get the first related model record matching the attributes or create it .
36,923
def sync ( self , ids , detaching = True ) : changes = { "attached" : [ ] , "detached" : [ ] , "updated" : [ ] } if isinstance ( ids , Collection ) : ids = ids . model_keys ( ) current = self . _new_pivot_query ( ) . lists ( self . _other_key ) . all ( ) records = self . _format_sync_list ( ids ) detach = [ x for x in current if x not in records . keys ( ) ] if detaching and len ( detach ) > 0 : self . detach ( detach ) changes [ "detached" ] = detach changes . update ( self . _attach_new ( records , current , False ) ) if len ( changes [ "attached" ] ) or len ( changes [ "updated" ] ) : self . touch_if_touching ( ) return changes
Sync the intermediate tables with a list of IDs or collection of models
36,924
def _format_sync_list ( self , records ) : results = { } for attributes in records : if not isinstance ( attributes , dict ) : id , attributes = attributes , { } else : id = list ( attributes . keys ( ) ) [ 0 ] attributes = attributes [ id ] results [ id ] = attributes return results
Format the sync list so that it is keyed by ID .
36,925
def attach ( self , id , attributes = None , touch = True ) : if isinstance ( id , orator . orm . Model ) : id = id . get_key ( ) query = self . new_pivot_statement ( ) if not isinstance ( id , list ) : id = [ id ] query . insert ( self . _create_attach_records ( id , attributes ) ) if touch : self . touch_if_touching ( )
Attach a model to the parent .
36,926
def _create_attach_records ( self , ids , attributes ) : records = [ ] timed = self . _has_pivot_column ( self . created_at ( ) ) or self . _has_pivot_column ( self . updated_at ( ) ) for key , value in enumerate ( ids ) : records . append ( self . _attacher ( key , value , attributes , timed ) ) return records
Create a list of records to insert into the pivot table .
36,927
def _attacher ( self , key , value , attributes , timed ) : id , extra = self . _get_attach_id ( key , value , attributes ) record = self . _create_attach_record ( id , timed ) if extra : record . update ( extra ) return record
Create a full attachment record payload .
36,928
def _get_attach_id ( self , key , value , attributes ) : if isinstance ( value , dict ) : key = list ( value . keys ( ) ) [ 0 ] attributes . update ( value [ key ] ) return [ key , attributes ] return value , attributes
Get the attach record ID and extra attributes .
36,929
def _set_timestamps_on_attach ( self , record , exists = False ) : fresh = self . _parent . fresh_timestamp ( ) if not exists and self . _has_pivot_column ( self . created_at ( ) ) : record [ self . created_at ( ) ] = fresh if self . _has_pivot_column ( self . updated_at ( ) ) : record [ self . updated_at ( ) ] = fresh return record
Set the creation an update timestamps on an attach record .
36,930
def detach ( self , ids = None , touch = True ) : if isinstance ( ids , orator . orm . model . Model ) : ids = ids . get_key ( ) if ids is None : ids = [ ] query = self . _new_pivot_query ( ) if not isinstance ( ids , list ) : ids = [ ids ] if len ( ids ) > 0 : query . where_in ( self . _other_key , ids ) if touch : self . touch_if_touching ( ) results = query . delete ( ) return results
Detach models from the relationship .
36,931
def touch_if_touching ( self ) : if self . _touching_parent ( ) : self . get_parent ( ) . touch ( ) if self . get_parent ( ) . touches ( self . _relation_name ) : self . touch ( )
Touch if the parent model is being touched .
36,932
def with_pivot ( self , * columns ) : columns = list ( columns ) self . _pivot_columns += columns return self
Set the columns on the pivot table to retrieve .
36,933
def with_timestamps ( self , created_at = None , updated_at = None ) : if not created_at : created_at = self . created_at ( ) if not updated_at : updated_at = self . updated_at ( ) return self . with_pivot ( created_at , updated_at )
Specify that the pivot table has creation and update columns .
36,934
def _get_eager_model_keys ( self , models ) : keys = [ ] for model in models : value = getattr ( model , self . _foreign_key ) if value is not None and value not in keys : keys . append ( value ) if not len ( keys ) : return [ 0 ] return keys
Gather the keys from a list of related models .
36,935
def update ( self , _attributes = None , ** attributes ) : if _attributes is not None : attributes . update ( _attributes ) instance = self . get_results ( ) return instance . fill ( attributes ) . save ( )
Update the parent model on the relationship .
36,936
def _build_dictionary ( self , models ) : 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 )
Build a dictionary with the models .
36,937
def get_eager ( self ) : for type in self . _dictionary . keys ( ) : self . _match_to_morph_parents ( type , self . _get_results_by_type ( type ) ) return self . _models
Get the relationship for eager loading .
36,938
def _match_to_morph_parents ( self , type , results ) : 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 ) )
Match the results for a given type to their parent .
36,939
def _get_results_by_type ( self , type ) : 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 ( )
Get all the relation results for a type .
36,940
def _gather_keys_by_type ( self , type ) : foreign = self . _foreign_key keys = ( BaseCollection . make ( list ( self . _dictionary [ type ] . values ( ) ) ) . map ( lambda models : getattr ( models [ 0 ] , foreign ) ) . unique ( ) ) return keys
Gather all of the foreign keys for a given type .
36,941
def set_primary_key ( self , columns , index_name = False ) : 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
Set the primary key .
36,942
def drop_index ( self , name ) : name = self . _normalize_identifier ( name ) if not self . has_index ( name ) : raise IndexDoesNotExist ( name , self . _name ) del self . _indexes [ name ]
Drops an index from this table .
36,943
def rename_index ( self , old_name , new_name = None ) : 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 ( ) )
Renames an index .
36,944
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 .
36,945
def _create_index ( self , columns , name , is_unique , is_primary , flags = None , options = None ) : 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 )
Creates an Index instance .
36,946
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 .
36,947
def change_column ( self , name , options ) : column = self . get_column ( name ) column . set_options ( options ) return self
Changes column details .
36,948
def drop_column ( self , name ) : name = self . _normalize_identifier ( name ) del self . _columns [ name ] return self
Drops a Column from the Table
36,949
def add_named_foreign_key_constraint ( self , name , foreign_table , local_columns , foreign_columns , options ) : 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
Adds a foreign key constraint with a given name .
36,950
def _add_index ( self , index ) : 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
Adds an index to the table .
36,951
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 .
36,952
def get_foreign_key ( self , name ) : name = self . _normalize_identifier ( name ) if not self . has_foreign_key ( name ) : raise ForeignKeyDoesNotExist ( name , self . _name ) return self . _fk_constraints [ name ]
Returns the foreign key constraint with the given name .
36,953
def remove_foreign_key ( self , name ) : name = self . _normalize_identifier ( name ) if not self . has_foreign_key ( name ) : raise ForeignKeyDoesNotExist ( name , self . _name ) del self . _fk_constraints [ name ]
Removes the foreign key constraint with the given name .
36,954
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_primary_key ( ) . get_columns ( )
Returns the primary key columns .
36,955
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 .
36,956
def get_index ( self , name ) : name = self . _normalize_identifier ( name ) if not self . has_index ( name ) : raise IndexDoesNotExist ( name , self . _name ) return self . _indexes [ name ]
Returns the Index with the given name .
36,957
def without_global_scope ( self , scope ) : 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
Remove a registered global scope .
36,958
def find_or_fail ( self , id , columns = None ) : 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__ )
Find a model by its primary key or raise an exception
36,959
def first_or_fail ( self , columns = None ) : model = self . first ( columns ) if model is not None : return model raise ModelNotFound ( self . _model . __class__ )
Execute the query and get the first result or raise an exception
36,960
def pluck ( self , column ) : result = self . first ( [ column ] ) if result : return result [ column ]
Pluck a single column from the database .
36,961
def _add_updated_at_column ( self , values ) : 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
Add the updated_at column to a dictionary of values .
36,962
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 .
36,963
def get_relation ( self , 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
Get the relation instance for the given relation name .
36,964
def _nested_relations ( self , relation ) : nested = { } for name , constraints in self . _eager_load . items ( ) : if self . _is_nested ( name , relation ) : nested [ name [ len ( relation + "." ) : ] ] = constraints return nested
Get the deeply nested relations for a given top - level relation .
36,965
def _is_nested ( self , name , relation ) : dots = name . find ( "." ) return dots and name . startswith ( relation + "." )
Determine if the relationship is nested .
36,966
def where_exists ( self , query , boolean = "and" , negate = False ) : if isinstance ( query , Builder ) : query = query . get_query ( ) self . get_query ( ) . where_exists ( query , boolean , negate ) return self
Add an exists clause to the query .
36,967
def has ( self , relation , operator = ">=" , count = 1 , boolean = "and" , extra = None ) : 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 ) if extra : if callable ( extra ) : extra ( query ) return self . _add_has_where ( query . apply_scopes ( ) , relation , operator , count , boolean )
Add a relationship count condition to the query .
36,968
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 ( count , basestring ) and count . isdigit ( ) : count = QueryExpression ( count ) return self . where ( QueryExpression ( "(%s)" % has_query . to_sql ( ) ) , operator , count , boolean )
Add the has condition where clause to the query .
36,969
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 , relation_query . get_bindings ( ) ) self . _query . add_binding ( has_query . get_query ( ) . get_bindings ( ) , "where" )
Merge the wheres from a relation query to a has query .
36,970
def apply_scopes ( self ) : if not self . _scopes : return self builder = copy . copy ( self ) query = builder . get_query ( ) original_where_count = len ( query . wheres ) where_counts = [ 0 , original_where_count ] for scope in self . _scopes . values ( ) : self . _apply_scope ( scope , builder ) 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
Get the underlying query builder instance with applied global scopes .
36,971
def _apply_scope ( self , scope , builder ) : if callable ( scope ) : scope ( builder ) elif isinstance ( scope , Scope ) : scope . apply ( builder , self . get_model ( ) )
Apply a single scope on the given builder instance .
36,972
def _nest_wheres_for_scope ( self , query , where_counts ) : wheres = query . wheres query . wheres = [ ] 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
Nest where conditions of the builder and each global scope .
36,973
def _slice_where_conditions ( self , wheres , offset , length ) : where_group = self . get_query ( ) . for_nested_where ( ) where_group . wheres = wheres [ offset : ( offset + length ) ] return { "type" : "nested" , "query" : where_group , "boolean" : "and" }
Create a where list with sliced where conditions .
36,974
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 .
36,975
def compile_insert ( self , query , values ) : table = self . wrap_table ( query . from__ ) if not isinstance ( values , list ) : values = [ values ] if len ( values ) == 1 : return super ( SQLiteQueryGrammar , self ) . compile_insert ( query , values ) names = self . columnize ( values [ 0 ] . keys ( ) ) columns = [ ] 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 ) , )
Compile insert statement into SQL
36,976
def compile_truncate ( self , query ) : sql = { "DELETE FROM sqlite_sequence WHERE name = %s" % self . get_marker ( ) : [ query . from__ ] } sql [ "DELETE FROM %s" % self . wrap_table ( query . from__ ) ] = [ ] return sql
Compile a truncate statement into SQL
36,977
def build ( self , connection , grammar ) : for statement in self . to_sql ( connection , grammar ) : connection . statement ( statement )
Execute the blueprint against the database .
36,978
def to_sql ( self , connection , grammar ) : 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
Get the raw SQL statements for the blueprint .
36,979
def _add_implied_commands ( self ) : 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 ( )
Add the commands that are implied by the blueprint .
36,980
def drop_column ( self , * columns ) : columns = list ( columns ) return self . _add_command ( "drop_column" , columns = columns )
Indicates that the given columns should be dropped .
36,981
def integer ( self , column , auto_increment = False , unsigned = False ) : return self . _add_column ( "integer" , column , auto_increment = auto_increment , unsigned = unsigned )
Create a new integer column on the table .
36,982
def small_integer ( self , column , auto_increment = False , unsigned = False ) : return self . _add_column ( "small_integer" , column , auto_increment = auto_increment , unsigned = unsigned )
Create a new small integer column on the table .
36,983
def unsigned_integer ( self , column , auto_increment = False ) : return self . integer ( column , auto_increment , True )
Create a new unisgned integer column on the table .
36,984
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 .
36,985
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 .
36,986
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 .
36,987
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 .
36,988
def timestamps ( self , use_current = True ) : if use_current : self . timestamp ( "created_at" ) . use_current ( ) self . timestamp ( "updated_at" ) . use_current ( ) else : self . timestamp ( "created_at" ) self . timestamp ( "updated_at" )
Create creation and update timestamps to the table .
36,989
def morphs ( self , name , index_name = None ) : self . unsigned_integer ( "%s_id" % name ) self . string ( "%s_type" % name ) self . index ( [ "%s_id" % name , "%s_type" % name ] , index_name )
Add the proper columns for a polymorphic table .
36,990
def _drop_index_command ( self , command , type , index ) : columns = [ ] if isinstance ( index , list ) : columns = index index = self . _create_index_name ( type , columns ) return self . _index_command ( command , columns , index )
Create a new drop index command on the blueprint .
36,991
def _index_command ( self , type , columns , index ) : 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 )
Add a new index command to the blueprint .
36,992
def _remove_column ( self , name ) : self . _columns = filter ( lambda c : c . name != name , self . _columns ) return self
Removes a column from the blueprint .
36,993
def _add_command ( self , name , ** parameters ) : command = self . _create_command ( name , ** parameters ) self . _commands . append ( command ) return command
Add a new command to the blueprint .
36,994
def get_quoted_columns ( self , platform ) : columns = [ ] for column in self . _columns . values ( ) : columns . append ( column . get_quoted_name ( platform ) ) return columns
Returns the quoted representation of the column names the constraint is associated with .
36,995
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 ) : 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
Checks if this index exactly spans the given column names in the correct order .
36,996
def is_fullfilled_by ( self , other ) : if len ( other . get_columns ( ) ) != len ( self . get_columns ( ) ) : return False if not self . spans_columns ( other . get_columns ( ) ) : return False if not self . same_partial_index ( other ) : return False if self . is_simple_index ( ) : return True if other . is_primary ( ) != self . is_primary ( ) : return False if other . is_unique ( ) != self . is_unique ( ) : return False return True
Checks if the other index already fulfills all the indexing and constraint needs of the current one .
36,997
def same_partial_index ( self , other ) : 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
Return whether the two indexes have the same partial index
36,998
def overrules ( self , other ) : 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
Detects if the other index is a non - unique non primary index that can be overwritten by this one .
36,999
def remove_flag ( self , flag ) : if self . has_flag ( flag ) : del self . _flags [ flag . lower ( ) ]
Removes a flag .