sequel_core 1.5.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +116 -0
- data/COPYING +19 -19
- data/README +83 -32
- data/Rakefile +9 -20
- data/bin/sequel +43 -112
- data/doc/cheat_sheet.rdoc +225 -0
- data/doc/dataset_filtering.rdoc +257 -0
- data/lib/sequel_core/adapters/adapter_skeleton.rb +4 -2
- data/lib/sequel_core/adapters/ado.rb +3 -1
- data/lib/sequel_core/adapters/db2.rb +4 -2
- data/lib/sequel_core/adapters/dbi.rb +127 -113
- data/lib/sequel_core/adapters/informix.rb +4 -2
- data/lib/sequel_core/adapters/jdbc.rb +5 -3
- data/lib/sequel_core/adapters/mysql.rb +112 -46
- data/lib/sequel_core/adapters/odbc.rb +5 -7
- data/lib/sequel_core/adapters/odbc_mssql.rb +12 -3
- data/lib/sequel_core/adapters/openbase.rb +3 -1
- data/lib/sequel_core/adapters/oracle.rb +11 -9
- data/lib/sequel_core/adapters/postgres.rb +261 -262
- data/lib/sequel_core/adapters/sqlite.rb +72 -22
- data/lib/sequel_core/connection_pool.rb +140 -73
- data/lib/sequel_core/core_ext.rb +201 -66
- data/lib/sequel_core/core_sql.rb +123 -153
- data/lib/sequel_core/database/schema.rb +156 -0
- data/lib/sequel_core/database.rb +321 -338
- data/lib/sequel_core/dataset/callback.rb +11 -12
- data/lib/sequel_core/dataset/convenience.rb +213 -240
- data/lib/sequel_core/dataset/pagination.rb +58 -43
- data/lib/sequel_core/dataset/parse_tree_sequelizer.rb +331 -0
- data/lib/sequel_core/dataset/query.rb +41 -0
- data/lib/sequel_core/dataset/schema.rb +15 -0
- data/lib/sequel_core/dataset/sequelizer.rb +41 -373
- data/lib/sequel_core/dataset/sql.rb +741 -632
- data/lib/sequel_core/dataset.rb +183 -168
- data/lib/sequel_core/deprecated.rb +1 -169
- data/lib/sequel_core/exceptions.rb +24 -19
- data/lib/sequel_core/migration.rb +44 -52
- data/lib/sequel_core/object_graph.rb +43 -42
- data/lib/sequel_core/pretty_table.rb +71 -76
- data/lib/sequel_core/schema/generator.rb +163 -105
- data/lib/sequel_core/schema/sql.rb +250 -93
- data/lib/sequel_core/schema.rb +2 -8
- data/lib/sequel_core/sql.rb +394 -0
- data/lib/sequel_core/worker.rb +37 -27
- data/lib/sequel_core.rb +99 -45
- data/spec/adapters/informix_spec.rb +0 -1
- data/spec/adapters/mysql_spec.rb +177 -124
- data/spec/adapters/oracle_spec.rb +0 -1
- data/spec/adapters/postgres_spec.rb +98 -58
- data/spec/adapters/sqlite_spec.rb +45 -4
- data/spec/blockless_filters_spec.rb +269 -0
- data/spec/connection_pool_spec.rb +21 -18
- data/spec/core_ext_spec.rb +169 -19
- data/spec/core_sql_spec.rb +56 -49
- data/spec/database_spec.rb +78 -17
- data/spec/dataset_spec.rb +300 -428
- data/spec/migration_spec.rb +1 -1
- data/spec/object_graph_spec.rb +5 -11
- data/spec/rcov.opts +1 -1
- data/spec/schema_generator_spec.rb +16 -4
- data/spec/schema_spec.rb +89 -10
- data/spec/sequelizer_spec.rb +56 -56
- data/spec/spec.opts +0 -5
- data/spec/spec_config.rb +7 -0
- data/spec/spec_config.rb.example +5 -5
- data/spec/spec_helper.rb +6 -0
- data/spec/worker_spec.rb +1 -1
- metadata +78 -63
| @@ -1,23 +1,19 @@ | |
| 1 | 
            -
            require File.join(File.dirname(__FILE__), '../../lib/sequel_core')
         | 
| 2 1 | 
             
            require File.join(File.dirname(__FILE__), '../spec_helper.rb')
         | 
| 3 2 |  | 
| 4 3 | 
             
            unless defined?(POSTGRES_DB)
         | 
| 5 | 
            -
               | 
| 4 | 
            +
              POSTGRES_URL = 'postgres://postgres:postgres@localhost:5432/reality_spec' unless defined? POSTGRES_URL
         | 
| 5 | 
            +
              POSTGRES_DB = Sequel.connect(ENV['SEQUEL_PG_SPEC_DB']||POSTGRES_URL)
         | 
| 6 6 | 
             
            end
         | 
| 7 7 |  | 
| 8 | 
            -
            POSTGRES_DB. | 
| 9 | 
            -
            POSTGRES_DB.drop_table(:test2) if POSTGRES_DB.table_exists?(:test2)
         | 
| 10 | 
            -
            POSTGRES_DB.drop_table(:test3) if POSTGRES_DB.table_exists?(:test3)
         | 
| 11 | 
            -
              
         | 
| 12 | 
            -
            POSTGRES_DB.create_table :test do
         | 
| 8 | 
            +
            POSTGRES_DB.create_table! :test do
         | 
| 13 9 | 
             
              text :name
         | 
| 14 10 | 
             
              integer :value, :index => true
         | 
| 15 11 | 
             
            end
         | 
| 16 | 
            -
            POSTGRES_DB.create_table :test2 do
         | 
| 12 | 
            +
            POSTGRES_DB.create_table! :test2 do
         | 
| 17 13 | 
             
              text :name
         | 
| 18 14 | 
             
              integer :value
         | 
| 19 15 | 
             
            end
         | 
| 20 | 
            -
            POSTGRES_DB.create_table :test3 do
         | 
| 16 | 
            +
            POSTGRES_DB.create_table! :test3 do
         | 
| 21 17 | 
             
              integer :value
         | 
| 22 18 | 
             
              timestamp :time
         | 
| 23 19 | 
             
            end
         | 
| @@ -37,6 +33,18 @@ context "A PostgreSQL database" do | |
| 37 33 | 
             
              specify "should provide the server version" do
         | 
| 38 34 | 
             
                @db.server_version.should > 70000
         | 
| 39 35 | 
             
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              specify "should raise Sequel::Error on error" do
         | 
| 38 | 
            +
                proc{@db << "SELECT 1 + 'a'"}.should raise_error(Sequel::Error)
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              specify "should correctly parse the schema" do
         | 
| 42 | 
            +
                @db.schema(:test3, :reload=>true).should == [[:value, {:type=>:integer, :allow_null=>true, :max_chars=>0, :default=>nil, :db_type=>"integer", :numeric_precision=>32}], [:time, {:type=>:datetime, :allow_null=>true, :max_chars=>0, :default=>nil, :db_type=>"timestamp without time zone", :numeric_precision=>0}]]
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              specify "should get the schema all database tables if no table name is used" do
         | 
| 46 | 
            +
                @db.schema(:test3, :reload=>true).should == @db.schema(nil, :reload=>true)[:test3]
         | 
| 47 | 
            +
              end
         | 
| 40 48 | 
             
            end
         | 
| 41 49 |  | 
| 42 50 | 
             
            context "A PostgreSQL dataset" do
         | 
| @@ -93,62 +101,64 @@ context "A PostgreSQL dataset" do | |
| 93 101 | 
             
                proc {@d.literal(false)}.should_not raise_error
         | 
| 94 102 | 
             
              end
         | 
| 95 103 |  | 
| 96 | 
            -
              specify "should quote columns using double quotes" do
         | 
| 104 | 
            +
              specify "should quote columns and tables using double quotes if quoting identifiers" do
         | 
| 105 | 
            +
                @d.quote_identifiers = true
         | 
| 97 106 | 
             
                @d.select(:name).sql.should == \
         | 
| 98 | 
            -
                  'SELECT "name" FROM test'
         | 
| 107 | 
            +
                  'SELECT "name" FROM "test"'
         | 
| 99 108 |  | 
| 100 109 | 
             
                @d.select('COUNT(*)'.lit).sql.should == \
         | 
| 101 | 
            -
                  'SELECT COUNT(*) FROM test'
         | 
| 110 | 
            +
                  'SELECT COUNT(*) FROM "test"'
         | 
| 102 111 |  | 
| 103 112 | 
             
                @d.select(:max[:value]).sql.should == \
         | 
| 104 | 
            -
                  'SELECT max("value") FROM test'
         | 
| 113 | 
            +
                  'SELECT max("value") FROM "test"'
         | 
| 105 114 |  | 
| 106 115 | 
             
                @d.select(:NOW[]).sql.should == \
         | 
| 107 | 
            -
                'SELECT NOW() FROM test'
         | 
| 116 | 
            +
                'SELECT NOW() FROM "test"'
         | 
| 108 117 |  | 
| 109 118 | 
             
                @d.select(:max[:items__value]).sql.should == \
         | 
| 110 | 
            -
                  'SELECT max(items."value") FROM test'
         | 
| 119 | 
            +
                  'SELECT max("items"."value") FROM "test"'
         | 
| 111 120 |  | 
| 112 121 | 
             
                @d.order(:name.desc).sql.should == \
         | 
| 113 | 
            -
                  'SELECT * FROM test ORDER BY "name" DESC'
         | 
| 122 | 
            +
                  'SELECT * FROM "test" ORDER BY "name" DESC'
         | 
| 114 123 |  | 
| 115 124 | 
             
                @d.select('test.name AS item_name'.lit).sql.should == \
         | 
| 116 | 
            -
                  'SELECT test.name AS item_name FROM test'
         | 
| 125 | 
            +
                  'SELECT test.name AS item_name FROM "test"'
         | 
| 117 126 |  | 
| 118 127 | 
             
                @d.select('"name"'.lit).sql.should == \
         | 
| 119 | 
            -
                  'SELECT "name" FROM test'
         | 
| 128 | 
            +
                  'SELECT "name" FROM "test"'
         | 
| 120 129 |  | 
| 121 130 | 
             
                @d.select('max(test."name") AS "max_name"'.lit).sql.should == \
         | 
| 122 | 
            -
                  'SELECT max(test."name") AS "max_name" FROM test'
         | 
| 131 | 
            +
                  'SELECT max(test."name") AS "max_name" FROM "test"'
         | 
| 123 132 |  | 
| 124 133 | 
             
                @d.select(:test[:abc, 'hello']).sql.should == \
         | 
| 125 | 
            -
                  "SELECT test(\"abc\", 'hello') FROM test"
         | 
| 134 | 
            +
                  "SELECT test(\"abc\", 'hello') FROM \"test\""
         | 
| 126 135 |  | 
| 127 136 | 
             
                @d.select(:test[:abc__def, 'hello']).sql.should == \
         | 
| 128 | 
            -
                  "SELECT test(abc.\"def\", 'hello') FROM test"
         | 
| 137 | 
            +
                  "SELECT test(\"abc\".\"def\", 'hello') FROM \"test\""
         | 
| 129 138 |  | 
| 130 139 | 
             
                @d.select(:test[:abc__def, 'hello'].as(:x2)).sql.should == \
         | 
| 131 | 
            -
                  "SELECT test(abc.\"def\", 'hello') AS \"x2\" FROM test"
         | 
| 140 | 
            +
                  "SELECT test(\"abc\".\"def\", 'hello') AS \"x2\" FROM \"test\""
         | 
| 132 141 |  | 
| 133 142 | 
             
                @d.insert_sql(:value => 333).should == \
         | 
| 134 | 
            -
                  'INSERT INTO test ("value") VALUES (333)'
         | 
| 143 | 
            +
                  'INSERT INTO "test" ("value") VALUES (333)'
         | 
| 135 144 |  | 
| 136 145 | 
             
                @d.insert_sql(:x => :y).should == \
         | 
| 137 | 
            -
                  'INSERT INTO test ("x") VALUES ("y")'
         | 
| 146 | 
            +
                  'INSERT INTO "test" ("x") VALUES ("y")'
         | 
| 138 147 | 
             
              end
         | 
| 139 148 |  | 
| 140 | 
            -
              specify "should quote fields correctly when reversing the order" do
         | 
| 149 | 
            +
              specify "should quote fields correctly when reversing the order if quoting identifiers" do
         | 
| 150 | 
            +
                @d.quote_identifiers = true
         | 
| 141 151 | 
             
                @d.reverse_order(:name).sql.should == \
         | 
| 142 | 
            -
                  'SELECT * FROM test ORDER BY "name" DESC'
         | 
| 152 | 
            +
                  'SELECT * FROM "test" ORDER BY "name" DESC'
         | 
| 143 153 |  | 
| 144 154 | 
             
                @d.reverse_order(:name.desc).sql.should == \
         | 
| 145 | 
            -
                  'SELECT * FROM test ORDER BY "name"'
         | 
| 155 | 
            +
                  'SELECT * FROM "test" ORDER BY "name"'
         | 
| 146 156 |  | 
| 147 157 | 
             
                @d.reverse_order(:name, :test.desc).sql.should == \
         | 
| 148 | 
            -
                  'SELECT * FROM test ORDER BY "name" DESC, "test"'
         | 
| 158 | 
            +
                  'SELECT * FROM "test" ORDER BY "name" DESC, "test"'
         | 
| 149 159 |  | 
| 150 160 | 
             
                @d.reverse_order(:name.desc, :test).sql.should == \
         | 
| 151 | 
            -
                  'SELECT * FROM test ORDER BY "name", "test" DESC'
         | 
| 161 | 
            +
                  'SELECT * FROM "test" ORDER BY "name", "test" DESC'
         | 
| 152 162 | 
             
              end
         | 
| 153 163 |  | 
| 154 164 | 
             
              specify "should support transactions" do
         | 
| @@ -159,6 +169,39 @@ context "A PostgreSQL dataset" do | |
| 159 169 | 
             
                @d.count.should == 1
         | 
| 160 170 | 
             
              end
         | 
| 161 171 |  | 
| 172 | 
            +
              specify "should correctly rollback transactions" do
         | 
| 173 | 
            +
                proc do
         | 
| 174 | 
            +
                  POSTGRES_DB.transaction do
         | 
| 175 | 
            +
                    @d << {:name => 'abc', :value => 1}
         | 
| 176 | 
            +
                    raise Interrupt, 'asdf'
         | 
| 177 | 
            +
                  end
         | 
| 178 | 
            +
                end.should raise_error(Interrupt)
         | 
| 179 | 
            +
             | 
| 180 | 
            +
                @d.count.should == 0
         | 
| 181 | 
            +
              end
         | 
| 182 | 
            +
              
         | 
| 183 | 
            +
              specify "should handle returning inside of the block by committing" do
         | 
| 184 | 
            +
                def POSTGRES_DB.ret_commit
         | 
| 185 | 
            +
                  transaction do
         | 
| 186 | 
            +
                    self[:test] << {:name => 'abc'}
         | 
| 187 | 
            +
                    return
         | 
| 188 | 
            +
                    self[:test] << {:name => 'd'}
         | 
| 189 | 
            +
                  end
         | 
| 190 | 
            +
                end
         | 
| 191 | 
            +
                @d.count.should == 0
         | 
| 192 | 
            +
                POSTGRES_DB.ret_commit
         | 
| 193 | 
            +
                @d.count.should == 1
         | 
| 194 | 
            +
                POSTGRES_DB.ret_commit
         | 
| 195 | 
            +
                @d.count.should == 2
         | 
| 196 | 
            +
                proc do
         | 
| 197 | 
            +
                  POSTGRES_DB.transaction do
         | 
| 198 | 
            +
                    raise Interrupt, 'asdf'
         | 
| 199 | 
            +
                  end
         | 
| 200 | 
            +
                end.should raise_error(Interrupt)
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                @d.count.should == 2
         | 
| 203 | 
            +
              end
         | 
| 204 | 
            +
             | 
| 162 205 | 
             
              specify "should support regexps" do
         | 
| 163 206 | 
             
                @d << {:name => 'abc', :value => 1}
         | 
| 164 207 | 
             
                @d << {:name => 'bcd', :value => 2}
         | 
| @@ -167,8 +210,8 @@ context "A PostgreSQL dataset" do | |
| 167 210 | 
             
              end
         | 
| 168 211 |  | 
| 169 212 | 
             
              specify "should consider strings containing backslashes to be escaped string literals" do
         | 
| 170 | 
            -
                 | 
| 171 | 
            -
                 | 
| 213 | 
            +
                @d.literal("\\dingo").should == "'\\\\dingo'"   # literally, E'\\dingo'
         | 
| 214 | 
            +
                @d.literal("dingo").should == "'dingo'"
         | 
| 172 215 | 
             
              end
         | 
| 173 216 | 
             
            end
         | 
| 174 217 |  | 
| @@ -191,22 +234,21 @@ context "A PostgreSQL database" do | |
| 191 234 | 
             
                @db = POSTGRES_DB
         | 
| 192 235 | 
             
              end
         | 
| 193 236 |  | 
| 194 | 
            -
              specify "should support  | 
| 237 | 
            +
              specify "should support column operations" do
         | 
| 238 | 
            +
                @db.create_table!(:test2){text :name; integer :value}
         | 
| 239 | 
            +
                @db[:test2] << {}
         | 
| 240 | 
            +
                @db[:test2].columns.should == [:name, :value]
         | 
| 241 | 
            +
             | 
| 195 242 | 
             
                @db.add_column :test2, :xyz, :text, :default => '000'
         | 
| 196 | 
            -
                
         | 
| 197 243 | 
             
                @db[:test2].columns.should == [:name, :value, :xyz]
         | 
| 198 244 | 
             
                @db[:test2] << {:name => 'mmm', :value => 111}
         | 
| 199 245 | 
             
                @db[:test2].first[:xyz].should == '000'
         | 
| 200 | 
            -
              end
         | 
| 201 246 |  | 
| 202 | 
            -
              specify "should support drop_column operations" do
         | 
| 203 247 | 
             
                @db[:test2].columns.should == [:name, :value, :xyz]
         | 
| 204 248 | 
             
                @db.drop_column :test2, :xyz
         | 
| 205 249 |  | 
| 206 250 | 
             
                @db[:test2].columns.should == [:name, :value]
         | 
| 207 | 
            -
              end
         | 
| 208 251 |  | 
| 209 | 
            -
              specify "should support rename_column operations" do
         | 
| 210 252 | 
             
                @db[:test2].delete
         | 
| 211 253 | 
             
                @db.add_column :test2, :xyz, :text, :default => '000'
         | 
| 212 254 | 
             
                @db[:test2] << {:name => 'mmm', :value => 111, :xyz => 'qqqq'}
         | 
| @@ -215,9 +257,7 @@ context "A PostgreSQL database" do | |
| 215 257 | 
             
                @db.rename_column :test2, :xyz, :zyx
         | 
| 216 258 | 
             
                @db[:test2].columns.should == [:name, :value, :zyx]
         | 
| 217 259 | 
             
                @db[:test2].first[:zyx].should == 'qqqq'
         | 
| 218 | 
            -
              end
         | 
| 219 260 |  | 
| 220 | 
            -
              specify "should support set_column_type operations" do
         | 
| 221 261 | 
             
                @db.add_column :test2, :xyz, :float
         | 
| 222 262 | 
             
                @db[:test2].delete
         | 
| 223 263 | 
             
                @db[:test2] << {:name => 'mmm', :value => 111, :xyz => 56.78}
         | 
| @@ -238,8 +278,8 @@ context "A PostgreSQL database" do | |
| 238 278 | 
             
                  full_text_index [:title, :body]
         | 
| 239 279 | 
             
                end
         | 
| 240 280 | 
             
                POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
         | 
| 241 | 
            -
                  "CREATE TABLE posts ( | 
| 242 | 
            -
                  "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector( | 
| 281 | 
            +
                  "CREATE TABLE posts (title text, body text)",
         | 
| 282 | 
            +
                  "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector(title || body))"
         | 
| 243 283 | 
             
                ]
         | 
| 244 284 | 
             
              end
         | 
| 245 285 |  | 
| @@ -250,20 +290,20 @@ context "A PostgreSQL database" do | |
| 250 290 | 
             
                  full_text_index [:title, :body], :language => 'french'
         | 
| 251 291 | 
             
                end
         | 
| 252 292 | 
             
                POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
         | 
| 253 | 
            -
                  "CREATE TABLE posts ( | 
| 254 | 
            -
                  "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector('french',  | 
| 293 | 
            +
                  "CREATE TABLE posts (title text, body text)",
         | 
| 294 | 
            +
                  "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector('french', title || body))"
         | 
| 255 295 | 
             
                ]
         | 
| 256 296 | 
             
              end
         | 
| 257 297 |  | 
| 258 298 | 
             
              specify "should support full_text_search" do
         | 
| 259 299 | 
             
                POSTGRES_DB[:posts].full_text_search(:title, 'ruby').sql.should ==
         | 
| 260 | 
            -
                  "SELECT * FROM posts WHERE (to_tsvector( | 
| 300 | 
            +
                  "SELECT * FROM posts WHERE (to_tsvector(title) @@ to_tsquery('ruby'))"
         | 
| 261 301 |  | 
| 262 302 | 
             
                POSTGRES_DB[:posts].full_text_search([:title, :body], ['ruby', 'sequel']).sql.should ==
         | 
| 263 | 
            -
                  "SELECT * FROM posts WHERE (to_tsvector( | 
| 303 | 
            +
                  "SELECT * FROM posts WHERE (to_tsvector(title || body) @@ to_tsquery('ruby | sequel'))"
         | 
| 264 304 |  | 
| 265 305 | 
             
                POSTGRES_DB[:posts].full_text_search(:title, 'ruby', :language => 'french').sql.should ==
         | 
| 266 | 
            -
                  "SELECT * FROM posts WHERE (to_tsvector('french',  | 
| 306 | 
            +
                  "SELECT * FROM posts WHERE (to_tsvector('french', title) @@ to_tsquery('french', 'ruby'))"
         | 
| 267 307 | 
             
              end
         | 
| 268 308 |  | 
| 269 309 | 
             
              specify "should support spatial indexes" do
         | 
| @@ -272,8 +312,8 @@ context "A PostgreSQL database" do | |
| 272 312 | 
             
                  spatial_index [:geom]
         | 
| 273 313 | 
             
                end
         | 
| 274 314 | 
             
                POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
         | 
| 275 | 
            -
                  "CREATE TABLE posts ( | 
| 276 | 
            -
                  "CREATE INDEX posts_geom_index ON posts USING gist ( | 
| 315 | 
            +
                  "CREATE TABLE posts (geom geometry)",
         | 
| 316 | 
            +
                  "CREATE INDEX posts_geom_index ON posts USING gist (geom)"
         | 
| 277 317 | 
             
                ]
         | 
| 278 318 | 
             
              end
         | 
| 279 319 |  | 
| @@ -283,8 +323,8 @@ context "A PostgreSQL database" do | |
| 283 323 | 
             
                  index :title, :type => 'hash'
         | 
| 284 324 | 
             
                end
         | 
| 285 325 | 
             
                POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
         | 
| 286 | 
            -
                  "CREATE TABLE posts ( | 
| 287 | 
            -
                  "CREATE INDEX posts_title_index ON posts USING hash ( | 
| 326 | 
            +
                  "CREATE TABLE posts (title varchar(5))",
         | 
| 327 | 
            +
                  "CREATE INDEX posts_title_index ON posts USING hash (title)"
         | 
| 288 328 | 
             
                ]
         | 
| 289 329 | 
             
              end
         | 
| 290 330 |  | 
| @@ -294,8 +334,8 @@ context "A PostgreSQL database" do | |
| 294 334 | 
             
                  index :title, :type => 'hash', :unique => true
         | 
| 295 335 | 
             
                end
         | 
| 296 336 | 
             
                POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
         | 
| 297 | 
            -
                  "CREATE TABLE posts ( | 
| 298 | 
            -
                  "CREATE UNIQUE INDEX posts_title_index ON posts USING hash ( | 
| 337 | 
            +
                  "CREATE TABLE posts (title varchar(5))",
         | 
| 338 | 
            +
                  "CREATE UNIQUE INDEX posts_title_index ON posts USING hash (title)"
         | 
| 299 339 | 
             
                ]
         | 
| 300 340 | 
             
              end
         | 
| 301 341 |  | 
| @@ -305,8 +345,8 @@ context "A PostgreSQL database" do | |
| 305 345 | 
             
                  index :title, :where => {:something => 5}
         | 
| 306 346 | 
             
                end
         | 
| 307 347 | 
             
                POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
         | 
| 308 | 
            -
                  "CREATE TABLE posts ( | 
| 309 | 
            -
                  "CREATE INDEX posts_title_index ON posts ( | 
| 348 | 
            +
                  "CREATE TABLE posts (title varchar(5))",
         | 
| 349 | 
            +
                  "CREATE INDEX posts_title_index ON posts (title) WHERE (something = 5)"
         | 
| 310 350 | 
             
                ]
         | 
| 311 351 | 
             
              end
         | 
| 312 352 | 
             
            end
         | 
| @@ -320,8 +360,8 @@ context "Postgres::Dataset#multi_insert_sql / #import" do | |
| 320 360 | 
             
                @ds.db.meta_def(:server_version) {80199}
         | 
| 321 361 |  | 
| 322 362 | 
             
                @ds.multi_insert_sql([:x, :y], [[1, 2], [3, 4]]).should == [
         | 
| 323 | 
            -
                  'INSERT INTO test ( | 
| 324 | 
            -
                  'INSERT INTO test ( | 
| 363 | 
            +
                  'INSERT INTO test (x, y) VALUES (1, 2)',
         | 
| 364 | 
            +
                  'INSERT INTO test (x, y) VALUES (3, 4)'
         | 
| 325 365 | 
             
                ]
         | 
| 326 366 | 
             
              end
         | 
| 327 367 |  | 
| @@ -329,13 +369,13 @@ context "Postgres::Dataset#multi_insert_sql / #import" do | |
| 329 369 | 
             
                @ds.db.meta_def(:server_version) {80200}
         | 
| 330 370 |  | 
| 331 371 | 
             
                @ds.multi_insert_sql([:x, :y], [[1, 2], [3, 4]]).should == [
         | 
| 332 | 
            -
                  'INSERT INTO test ( | 
| 372 | 
            +
                  'INSERT INTO test (x, y) VALUES (1, 2), (3, 4)'
         | 
| 333 373 | 
             
                ]
         | 
| 334 374 |  | 
| 335 375 | 
             
                @ds.db.meta_def(:server_version) {80201}
         | 
| 336 376 |  | 
| 337 377 | 
             
                @ds.multi_insert_sql([:x, :y], [[1, 2], [3, 4]]).should == [
         | 
| 338 | 
            -
                  'INSERT INTO test ( | 
| 378 | 
            +
                  'INSERT INTO test (x, y) VALUES (1, 2), (3, 4)'
         | 
| 339 379 | 
             
                ]
         | 
| 340 380 | 
             
              end
         | 
| 341 381 | 
             
            end
         | 
| @@ -1,4 +1,3 @@ | |
| 1 | 
            -
            require File.join(File.dirname(__FILE__), '../../lib/sequel_core')
         | 
| 2 1 | 
             
            require File.join(File.dirname(__FILE__), '../spec_helper.rb')
         | 
| 3 2 |  | 
| 4 3 | 
             
            unless defined?(SQLITE_DB)
         | 
| @@ -17,9 +16,12 @@ end | |
| 17 16 | 
             
            SQLITE_DB.create_table(:time) {timestamp :t}
         | 
| 18 17 |  | 
| 19 18 | 
             
            context "An SQLite database" do
         | 
| 20 | 
            -
               | 
| 19 | 
            +
              before do
         | 
| 21 20 | 
             
                @db = Sequel.connect('sqlite:/')
         | 
| 22 21 | 
             
              end
         | 
| 22 | 
            +
              after do
         | 
| 23 | 
            +
                @db.disconnect
         | 
| 24 | 
            +
              end
         | 
| 23 25 |  | 
| 24 26 | 
             
              specify "should provide a list of existing tables" do
         | 
| 25 27 | 
             
                @db.tables.should == []
         | 
| @@ -37,13 +39,15 @@ context "An SQLite database" do | |
| 37 39 | 
             
              specify "should support setting pragma values" do
         | 
| 38 40 | 
             
                @db.pragma_set(:auto_vacuum, '1')
         | 
| 39 41 | 
             
                @db.pragma_get(:auto_vacuum).should == '1'
         | 
| 42 | 
            +
                @db.pragma_set(:auto_vacuum, '2')
         | 
| 43 | 
            +
                @db.pragma_get(:auto_vacuum).should == '2'
         | 
| 40 44 | 
             
              end
         | 
| 41 45 |  | 
| 42 46 | 
             
              specify "should support getting and setting the auto_vacuum pragma" do
         | 
| 43 47 | 
             
                @db.auto_vacuum = :full
         | 
| 44 48 | 
             
                @db.auto_vacuum.should == :full
         | 
| 45 | 
            -
                @db.auto_vacuum = : | 
| 46 | 
            -
                @db.auto_vacuum.should == : | 
| 49 | 
            +
                @db.auto_vacuum = :incremental
         | 
| 50 | 
            +
                @db.auto_vacuum.should == :incremental
         | 
| 47 51 |  | 
| 48 52 | 
             
                proc {@db.auto_vacuum = :invalid}.should raise_error(Sequel::Error)
         | 
| 49 53 | 
             
              end
         | 
| @@ -123,6 +127,29 @@ context "An SQLite database" do | |
| 123 127 | 
             
                @db.tables.should == [:t]
         | 
| 124 128 | 
             
              end
         | 
| 125 129 |  | 
| 130 | 
            +
              specify "should handle returning inside of transaction by committing" do
         | 
| 131 | 
            +
                @db.create_table(:items){text :name}
         | 
| 132 | 
            +
                def @db.ret_commit
         | 
| 133 | 
            +
                  transaction do
         | 
| 134 | 
            +
                    self[:items] << {:name => 'abc'}
         | 
| 135 | 
            +
                    return
         | 
| 136 | 
            +
                    self[:items] << {:name => 'd'}
         | 
| 137 | 
            +
                  end
         | 
| 138 | 
            +
                end
         | 
| 139 | 
            +
                @db[:items].count.should == 0
         | 
| 140 | 
            +
                @db.ret_commit
         | 
| 141 | 
            +
                @db[:items].count.should == 1
         | 
| 142 | 
            +
                @db.ret_commit
         | 
| 143 | 
            +
                @db[:items].count.should == 2
         | 
| 144 | 
            +
                proc do
         | 
| 145 | 
            +
                  @db.transaction do
         | 
| 146 | 
            +
                    raise Interrupt, 'asdf'
         | 
| 147 | 
            +
                  end
         | 
| 148 | 
            +
                end.should raise_error(Interrupt)
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                @db[:items].count.should == 2
         | 
| 151 | 
            +
              end
         | 
| 152 | 
            +
             | 
| 126 153 | 
             
              specify "should provide disconnect functionality" do
         | 
| 127 154 | 
             
                @db.tables
         | 
| 128 155 | 
             
                @db.pool.size.should == 1
         | 
| @@ -162,6 +189,20 @@ context "An SQLite database" do | |
| 162 189 | 
             
                proc {@db.single_value 'blah blah'}.should raise_error(
         | 
| 163 190 | 
             
                  Sequel::Error::InvalidStatement, "blah blah\r\nnear \"blah\": syntax error")
         | 
| 164 191 | 
             
              end
         | 
| 192 | 
            +
              
         | 
| 193 | 
            +
              specify "should not swallow non-SQLite based exceptions" do
         | 
| 194 | 
            +
                proc {@db.pool.hold{raise Interrupt, "test"}}.should raise_error(Interrupt)
         | 
| 195 | 
            +
              end
         | 
| 196 | 
            +
             | 
| 197 | 
            +
              specify "should correctly parse the schema" do
         | 
| 198 | 
            +
                @db.create_table(:time) {timestamp :t}
         | 
| 199 | 
            +
                @db.schema(:time, :reload=>true).should == [[:t, {:type=>:datetime, :allow_null=>true, :max_chars=>nil, :default=>nil, :db_type=>"timestamp", :numeric_precision=>nil, :primary_key=>false}]]
         | 
| 200 | 
            +
              end
         | 
| 201 | 
            +
             | 
| 202 | 
            +
              specify "should get the schema all database tables if no table name is used" do
         | 
| 203 | 
            +
                @db.create_table(:time) {timestamp :t}
         | 
| 204 | 
            +
                @db.schema(:time, :reload=>true).should == @db.schema(nil, :reload=>true)[:time]
         | 
| 205 | 
            +
              end
         | 
| 165 206 | 
             
            end
         | 
| 166 207 |  | 
| 167 208 | 
             
            context "An SQLite dataset" do
         |