Question

sequel interprets tinyint(1) fields as a boolean type. While reasonable most of the time, is there a way to get to the real integer value?

mysql> CREATE TABLE t1 (f1 TINYINT(1));

mysql> INSERT INTO t1 VALUES (0), (1), (2);

$ type 1.rb
#!/usr/bin/env ruby
require 'sequel'
require 'pp'
$DB = Sequel.connect(
    adapter: 'mysql2',
    database: 'd1',
    user: 'u1',
    password: '...',
)
pp $DB[:t1].all
$ ./1.rb
[{:f1=>false}, {:f1=>true}, {:f1=>true}]
Was it helpful?

Solution

It looks like this might be what you need: http://sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/MySQL.html

specifically, calling

Sequel::MySQL.convert_tinyint_to_bool = false

somewhere in your initialisation code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top