| Module | Sequel::MySQL::DatabaseMethods |
| In: |
lib/sequel_core/adapters/shared/mysql.rb
|
| AUTO_INCREMENT | = | 'AUTO_INCREMENT'.freeze |
| NOT_NULL | = | Sequel::Schema::SQL::NOT_NULL |
| NULL | = | Sequel::Schema::SQL::NULL |
| PRIMARY_KEY | = | Sequel::Schema::SQL::PRIMARY_KEY |
| TYPES | = | Sequel::Schema::SQL::TYPES.merge(DateTime=>'datetime', \ TrueClass=>'tinyint', FalseClass=>'tinyint') |
| UNIQUE | = | Sequel::Schema::SQL::UNIQUE |
| UNSIGNED | = | Sequel::Schema::SQL::UNSIGNED |
Use MySQL specific syntax for rename column, set column type, and drop index cases.
# File lib/sequel_core/adapters/shared/mysql.rb, line 26
26: def alter_table_sql(table, op)
27: case op[:op]
28: when :add_column
29: if related = op.delete(:table)
30: sql = super(table, op)
31: op[:table] = related
32: [sql, "ALTER TABLE #{quote_schema_table(table)} ADD FOREIGN KEY (#{quote_identifier(op[:name])})#{default_column_references_sql(op)}"]
33: else
34: super(table, op)
35: end
36: when :rename_column
37: "ALTER TABLE #{quote_schema_table(table)} CHANGE COLUMN #{quote_identifier(op[:name])} #{quote_identifier(op[:new_name])} #{type_literal(op)}"
38: when :set_column_type
39: "ALTER TABLE #{quote_schema_table(table)} CHANGE COLUMN #{quote_identifier(op[:name])} #{quote_identifier(op[:name])} #{type_literal(op)}"
40: when :drop_index
41: "#{drop_index_sql(table, op)} ON #{quote_schema_table(table)}"
42: else
43: super(table, op)
44: end
45: end
Use MySQL specific syntax for engine type and character encoding
# File lib/sequel_core/adapters/shared/mysql.rb, line 58
58: def create_table_sql_list(name, columns, indexes = nil, options = {})
59: options[:engine] = Sequel::MySQL.default_engine unless options.include?(:engine)
60: options[:charset] = Sequel::MySQL.default_charset unless options.include?(:charset)
61: options[:collate] = Sequel::MySQL.default_collate unless options.include?(:collate)
62: sql = ["CREATE TABLE #{quote_schema_table(name)} (#{column_list_sql(columns)})#{" ENGINE=#{options[:engine]}" if options[:engine]}#{" DEFAULT CHARSET=#{options[:charset]}" if options[:charset]}#{" DEFAULT COLLATE=#{options[:collate]}" if options[:collate]}"]
63: sql.concat(index_list_sql_list(name, indexes)) if indexes && !indexes.empty?
64: sql
65: end
Handle MySQL specific index SQL syntax
# File lib/sequel_core/adapters/shared/mysql.rb, line 68
68: def index_definition_sql(table_name, index)
69: index_name = quote_identifier(index[:name] || default_index_name(table_name, index[:columns]))
70: index_type = case index[:type]
71: when :full_text
72: "FULLTEXT "
73: when :spatial
74: "SPATIAL "
75: else
76: using = " USING #{index[:type]}" unless index[:type] == nil
77: "UNIQUE " if index[:unique]
78: end
79: "CREATE #{index_type}INDEX #{index_name} ON #{quote_schema_table(table_name)} #{literal(index[:columns])}#{using}"
80: end
Get version of MySQL server, used for determined capabilities.
# File lib/sequel_core/adapters/shared/mysql.rb, line 83
83: def server_version
84: m = /(\d+)\.(\d+)\.(\d+)/.match(get(SQL::Function.new(:version)))
85: @server_version ||= (m[1].to_i * 10000) + (m[2].to_i * 100) + m[3].to_i
86: end
Return an array of symbols specifying table names in the current database.
Options:
# File lib/sequel_core/adapters/shared/mysql.rb, line 92
92: def tables(opts={})
93: ds = self['SHOW TABLES'].server(opts[:server])
94: ds.identifier_output_method = nil
95: ds2 = dataset
96: ds.map{|r| ds2.send(:output_identifier, r.values.first)}
97: end