<s> from . grammar import SchemaGrammar <EOL> from . . blueprint import Blueprint <EOL> from ... query . expression import QueryExpression <EOL> from ... support . fluent import Fluent <EOL> class SQLiteSchemaGrammar ( SchemaGrammar ) : <EOL> _modifiers = [ '<STR_LIT>' , '<STR_LIT:default>' , '<STR_LIT>' ] <EOL> _serials = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def compile_rename_column ( self , blueprint , command , connection ) : <EOL> """<STR_LIT>""" <EOL> sql = [ ] <EOL> foreign_keys = self . _connection . select ( '<STR_LIT>' ) <EOL> if foreign_keys : <EOL> foreign_keys = bool ( foreign_keys [ <NUM_LIT:0> ] ) <EOL> if foreign_keys : <EOL> sql . append ( '<STR_LIT>' ) <EOL> sql += super ( SQLiteSchemaGrammar , self ) . compile_rename_column ( blueprint , command , connection ) <EOL> if foreign_keys : <EOL> sql . append ( '<STR_LIT>' ) <EOL> return sql <EOL> def compile_change ( self , blueprint , command , connection ) : <EOL> """<STR_LIT>""" <EOL> sql = [ ] <EOL> foreign_keys = self . _connection . select ( '<STR_LIT>' ) <EOL> if foreign_keys : <EOL> foreign_keys = bool ( foreign_keys [ <NUM_LIT:0> ] ) <EOL> if foreign_keys : <EOL> sql . append ( '<STR_LIT>' ) <EOL> sql += super ( SQLiteSchemaGrammar , self ) . compile_change ( blueprint , command , connection ) <EOL> if foreign_keys : <EOL> sql . append ( '<STR_LIT>' ) <EOL> return sql <EOL> def compile_table_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def compile_column_exists ( self , table ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % table . replace ( '<STR_LIT:.>' , '<STR_LIT>' ) <EOL> def compile_create ( self , blueprint , command , _ ) : <EOL> """<STR_LIT>""" <EOL> columns = '<STR_LIT:U+002CU+0020>' . join ( self . _get_columns ( blueprint ) ) <EOL> sql = '<STR_LIT>' % ( self . wrap_table ( blueprint ) , columns ) <EOL> sql += self . _add_foreign_keys ( blueprint ) <EOL> sql += self . _add_primary_keys ( blueprint ) <EOL> return sql + '<STR_LIT:)>' <EOL> def _add_foreign_keys ( self , blueprint ) : <EOL> sql = '<STR_LIT>' <EOL> foreigns = self . _get_commands_by_name ( blueprint , '<STR_LIT>' ) <EOL> for foreign in foreigns : <EOL> sql += self . _get_foreign_key ( foreign ) <EOL> if foreign . get ( '<STR_LIT>' ) : <EOL> sql += '<STR_LIT>' % foreign . on_delete <EOL> if foreign . get ( '<STR_LIT>' ) : <EOL> sql += '<STR_LIT>' % foreign . on_delete <EOL> return sql <EOL> def _get_foreign_key ( self , foreign ) : <EOL> on = self . wrap_table ( foreign . on ) <EOL> columns = self . columnize ( foreign . columns ) <EOL> references = foreign . references <EOL> if not isinstance ( references , list ) : <EOL> references = [ references ] <EOL> on_columns = self . columnize ( references ) <EOL> return '<STR_LIT>' % ( columns , on , on_columns ) <EOL> def _add_primary_keys ( self , blueprint ) : <EOL> primary = self . _get_command_by_name ( blueprint , '<STR_LIT>' ) <EOL> if primary : <EOL> columns = self . columnize ( primary . columns ) <EOL> return '<STR_LIT>' % columns <EOL> return '<STR_LIT>' <EOL> def compile_add ( self , blueprint , command , _ ) : <EOL> table = self . wrap_table ( blueprint ) <EOL> columns = self . prefix_list ( '<STR_LIT>' , self . _get_columns ( blueprint ) ) <EOL> statements = [ ] <EOL> for column in columns : <EOL> statements . append ( '<STR_LIT>' % ( table , column ) ) <EOL> return statements <EOL> def compile_unique ( self , blueprint , command , _ ) : <EOL> columns = self . columnize ( command . columns ) <EOL> table = self . wrap_table ( blueprint ) <EOL> return '<STR_LIT>' % ( command . index , table , columns ) <EOL> def compile_index ( self , blueprint , command , _ ) : <EOL> columns = self . columnize ( command . columns ) <EOL> table = self . wrap_table ( blueprint ) <EOL> return '<STR_LIT>' % ( command . index , table , columns ) <EOL> def compile_foreign ( self , blueprint , command , _ ) : <EOL> pass <EOL> def compile_drop ( self , blueprint , command , _ ) : <EOL> return '<STR_LIT>' % self . wrap_table ( blueprint ) <EOL> def compile_drop_if_exists ( self , blueprint , command , _ ) : <EOL> return '<STR_LIT>' % self . wrap_table ( blueprint ) <EOL> def compile_drop_column ( self , blueprint , command , connection ) : <EOL> schema = connection . get_schema_manager ( ) <EOL> table_diff = self . _get_table_diff ( blueprint , schema ) <EOL> for name in command . columns : <EOL> column = connection . get_column ( blueprint . get_table ( ) , name ) <EOL> table_diff . removed_columns [ name ] = column <EOL> return schema . get_database_platform ( ) . get_alter_table_sql ( table_diff ) <EOL> def compile_drop_unique ( self , blueprint , command , _ ) : <EOL> return '<STR_LIT>' % command . index <EOL> def compile_drop_index ( self , blueprint , command , _ ) : <EOL> return '<STR_LIT>' % command . index <EOL> def compile_rename ( self , blueprint , command , _ ) : <EOL> from_ = self . wrap_table ( blueprint ) <EOL> return '<STR_LIT>' % ( from_ , self . wrap_table ( command . to ) ) <EOL> def _type_char ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_string ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_text ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_medium_text ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_long_text ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_integer ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_big_integer ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_medium_integer ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_tiny_integer ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_small_integer ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_float ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_double ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_decimal ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_boolean ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_enum ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_json ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_date ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_datetime ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_time ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _type_timestamp ( self , column ) : <EOL> if column . use_current : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> def _type_binary ( self , column ) : <EOL> return '<STR_LIT>' <EOL> def _modify_nullable ( self , blueprint , column ) : <EOL> if column . get ( '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> def _modify_default ( self , blueprint , column ) : <EOL> if column . get ( '<STR_LIT:default>' ) is not None : <EOL> return '<STR_LIT>' % self . _get_default_value ( column . default ) <EOL> return '<STR_LIT>' <EOL> def _modify_increment ( self , blueprint , column ) : <EOL> if column . type in self . _serials and column . auto_increment : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' </s>
