Module | Sequel::MySQL::DatasetMethods |
In: |
lib/sequel/adapters/shared/mysql.rb
|
BOOL_TRUE | = | '1'.freeze |
BOOL_FALSE | = | '0'.freeze |
COMMA_SEPARATOR | = | ', '.freeze |
FOR_SHARE | = | ' LOCK IN SHARE MODE'.freeze |
DELETE_CLAUSE_METHODS | = | Dataset.clause_methods(:delete, %w'from where order limit') |
INSERT_CLAUSE_METHODS | = | Dataset.clause_methods(:insert, %w'ignore into columns values on_duplicate_key_update') |
SELECT_CLAUSE_METHODS | = | Dataset.clause_methods(:select, %w'distinct columns from join where group having compounds order limit lock') |
UPDATE_CLAUSE_METHODS | = | Dataset.clause_methods(:update, %w'table set where order limit') |
MySQL specific syntax for LIKE/REGEXP searches, as well as string concatenation.
# File lib/sequel/adapters/shared/mysql.rb, line 294 294: def complex_expression_sql(op, args) 295: case op 296: when :~, '!~''!~', '~*''~*', '!~*''!~*', :LIKE, 'NOT LIKE''NOT LIKE', :ILIKE, 'NOT ILIKE''NOT ILIKE' 297: "(#{literal(args.at(0))} #{'NOT ' if [:'NOT LIKE', :'NOT ILIKE', :'!~', :'!~*'].include?(op)}#{[:~, :'!~', :'~*', :'!~*'].include?(op) ? 'REGEXP' : 'LIKE'} #{'BINARY ' if [:~, :'!~', :LIKE, :'NOT LIKE'].include?(op)}#{literal(args.at(1))})" 298: when '||''||' 299: if args.length > 1 300: "CONCAT(#{args.collect{|a| literal(a)}.join(', ')})" 301: else 302: literal(args.at(0)) 303: end 304: when 'B~''B~' 305: "CAST(~#{literal(args.at(0))} AS SIGNED INTEGER)" 306: else 307: super(op, args) 308: end 309: end
Use GROUP BY instead of DISTINCT ON if arguments are provided.
# File lib/sequel/adapters/shared/mysql.rb, line 312 312: def distinct(*args) 313: args.empty? ? super : group(*args) 314: end
Return a cloned dataset which will use LOCK IN SHARE MODE to lock returned rows.
# File lib/sequel/adapters/shared/mysql.rb, line 317 317: def for_share 318: lock_style(:share) 319: end
Adds full text filter
# File lib/sequel/adapters/shared/mysql.rb, line 322 322: def full_text_search(cols, terms, opts = {}) 323: filter(full_text_sql(cols, terms, opts)) 324: end
Sets up the insert methods to use INSERT IGNORE. Useful if you have a unique key and want to just skip inserting rows that violate the unique key restriction.
dataset.insert_ignore.multi_insert( [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}] ) # INSERT IGNORE INTO tablename (name, value) VALUES (a, 1), (b, 2)
# File lib/sequel/adapters/shared/mysql.rb, line 362 362: def insert_ignore 363: clone(:insert_ignore=>true) 364: end
Transforms an CROSS JOIN to an INNER JOIN if the expr is not nil. Raises an error on use of :full_outer type, since MySQL doesn‘t support it.
# File lib/sequel/adapters/shared/mysql.rb, line 338 338: def join_table(type, table, expr=nil, table_alias={}) 339: type = :inner if (type == :cross) && !expr.nil? 340: raise(Sequel::Error, "MySQL doesn't support FULL OUTER JOIN") if type == :full_outer 341: super(type, table, expr, table_alias) 342: end
Transforms :natural_inner to NATURAL LEFT JOIN and straight to STRAIGHT_JOIN.
# File lib/sequel/adapters/shared/mysql.rb, line 346 346: def join_type_sql(join_type) 347: case join_type 348: when :straight then 'STRAIGHT_JOIN' 349: when :natural_inner then 'NATURAL LEFT JOIN' 350: else super 351: end 352: end
Sets up the insert methods to use ON DUPLICATE KEY UPDATE If you pass no arguments, ALL fields will be updated with the new values. If you pass the fields you want then ONLY those field will be updated.
Useful if you have a unique key and want to update inserting rows that violate the unique key restriction.
dataset.on_duplicate_key_update.multi_insert( [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}] ) # INSERT INTO tablename (name, value) VALUES (a, 1), (b, 2) # ON DUPLICATE KEY UPDATE name=VALUES(name), value=VALUES(value) dataset.on_duplicate_key_update(:value).multi_insert( [{:name => 'a', :value => 1}, {:name => 'b', :value => 2}] ) # INSERT INTO tablename (name, value) VALUES (a, 1), (b, 2) # ON DUPLICATE KEY UPDATE value=VALUES(value)
# File lib/sequel/adapters/shared/mysql.rb, line 385 385: def on_duplicate_key_update(*args) 386: clone(:on_duplicate_key_update => args) 387: end
MySQL does support fractional timestamps in literal timestamps, but it ignores them. Also, using them seems to cause problems on 1.9. Since they are ignored anyway, not using them is probably best.
# File lib/sequel/adapters/shared/mysql.rb, line 430 430: def supports_timestamp_usecs? 431: false 432: end