Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge sequel_core directory into sequel directory

This is the first half of the merge, the merge of sequel_model into
sequel will come next.  I'm going this because it makes things
cleaner.  I've wanted to do this for a while, but it wasn't worth
the minor breakage.  Now that Sequel 3.0 is coming soon, it seemed
like a good time.

To make life easier and to allow for more flexibility, I'm adding
a Sequel.require method that simplifies requiring multiple files.
It also only loads files in the same directory or a subdirectory
of the directory containing lib/sequel/core.rb.  Sequel used to do
this many moons ago, and I removed it to give users more flexibility
to override stuff.  I've come to the conclusion that removing it
caused more problems than it solved.  There have been a couple of
cases during the recent refactoring where I got obscure errors
because I deleted a file but still had it required somewhere, and it
loaded a file in a previous gem.  If people want to customize sequel,
they should fork the repository or unpack the gem to make their
modifications.

This requires simple changes to all adapters.  I hope I didn't screw
anything up, but it should be easy to fix if I did.

This also fixes a reference to Schema::SQL in the shared MySQL
adapter.
  • Loading branch information...
commit 88e9e93712a9906a4aa8ec86782d62681a860a60 1 parent d6db9f7
@jeremyevans jeremyevans authored
Showing with 250 additions and 255 deletions.
  1. +2 −2 Rakefile
  2. +2 −2 lib/{sequel_core → sequel}/adapters/ado.rb
  3. 0  lib/{sequel_core → sequel}/adapters/db2.rb
  4. 0  lib/{sequel_core → sequel}/adapters/dbi.rb
  5. +3 −3 lib/{sequel_core → sequel}/adapters/do.rb
  6. +1 −1  lib/{sequel_core → sequel}/adapters/do/mysql.rb
  7. +1 −1  lib/{sequel_core → sequel}/adapters/do/postgres.rb
  8. +1 −1  lib/{sequel_core → sequel}/adapters/do/sqlite.rb
  9. +1 −1  lib/{sequel_core → sequel}/adapters/firebird.rb
  10. +1 −1  lib/{sequel_core → sequel}/adapters/informix.rb
  11. +7 −7 lib/{sequel_core → sequel}/adapters/jdbc.rb
  12. +1 −2  lib/{sequel_core → sequel}/adapters/jdbc/h2.rb
  13. +1 −1  lib/{sequel_core → sequel}/adapters/jdbc/mysql.rb
  14. +1 −1  lib/{sequel_core → sequel}/adapters/jdbc/oracle.rb
  15. +1 −1  lib/{sequel_core → sequel}/adapters/jdbc/postgresql.rb
  16. +1 −1  lib/{sequel_core → sequel}/adapters/jdbc/sqlite.rb
  17. +1 −2  lib/{sequel_core → sequel}/adapters/mysql.rb
  18. +2 −2 lib/{sequel_core → sequel}/adapters/odbc.rb
  19. 0  lib/{sequel_core → sequel}/adapters/openbase.rb
  20. +1 −1  lib/{sequel_core → sequel}/adapters/oracle.rb
  21. +1 −1  lib/{sequel_core → sequel}/adapters/postgres.rb
  22. +1 −1  lib/{sequel_core → sequel}/adapters/shared/mssql.rb
  23. +4 −6 lib/{sequel_core → sequel}/adapters/shared/mysql.rb
  24. +1 −2  lib/{sequel_core → sequel}/adapters/shared/oracle.rb
  25. 0  lib/{sequel_core → sequel}/adapters/shared/postgres.rb
  26. +1 −2  lib/{sequel_core → sequel}/adapters/shared/progress.rb
  27. +1 −1  lib/{sequel_core → sequel}/adapters/shared/sqlite.rb
  28. +1 −1  lib/{sequel_core → sequel}/adapters/sqlite.rb
  29. 0  lib/{sequel_core → sequel}/adapters/utils/date_format.rb
  30. 0  lib/{sequel_core → sequel}/adapters/utils/stored_procedures.rb
  31. 0  lib/{sequel_core → sequel}/adapters/utils/unsupported.rb
  32. 0  lib/{sequel_core → sequel}/connection_pool.rb
  33. +204 −0 lib/sequel/core.rb
  34. 0  lib/{sequel_core → sequel}/core_ext.rb
  35. 0  lib/{sequel_core → sequel}/core_sql.rb
  36. +1 −3 lib/{sequel_core → sequel}/database.rb
  37. 0  lib/{sequel_core → sequel}/database/schema_generator.rb
  38. 0  lib/{sequel_core → sequel}/database/schema_methods.rb
  39. 0  lib/{sequel_core → sequel}/database/schema_sql.rb
  40. +0 −4 lib/{sequel_core → sequel}/dataset.rb
  41. 0  lib/{sequel_core → sequel}/dataset/convenience.rb
  42. 0  lib/{sequel_core → sequel}/dataset/prepared_statements.rb
  43. 0  lib/{sequel_core → sequel}/dataset/sql.rb
  44. 0  lib/{sequel_core → sequel}/deprecated.rb
  45. 0  lib/{sequel_core → sequel}/exceptions.rb
  46. 0  lib/{sequel_core → sequel}/metaprogramming.rb
  47. 0  lib/{sequel_core → sequel}/migration.rb
  48. 0  lib/{sequel_core → sequel}/object_graph.rb
  49. 0  lib/{sequel_core → sequel}/sql.rb
  50. 0  lib/{sequel_core → sequel}/version.rb
  51. +1 −198 lib/sequel_core.rb
  52. +1 −1  lib/sequel_model.rb
  53. +1 −1  spec/adapters/spec_helper.rb
  54. +1 −1  spec/extensions/spec_helper.rb
  55. +1 −1  spec/sequel_core/database_spec.rb
  56. +1 −1  spec/sequel_core/spec_helper.rb
  57. +1 −1  spec/sequel_model/spec_helper.rb
View
4 Rakefile
@@ -8,7 +8,7 @@ rescue LoadError
require "rake/rdoctask"
end
require "fileutils"
-require "lib/sequel_core/version"
+require "lib/sequel/version"
include FileUtils
@@ -61,7 +61,7 @@ task :uninstall=>[:clean] do
sh %{sudo gem uninstall #{NAME}}
end
-desc "Upload sequel and sequel_core gems to rubyforge"
+desc "Upload sequel gem to rubyforge"
task :release=>[:package] do
sh %{rubyforge login}
sh %{rubyforge add_release sequel #{NAME} #{VERS} pkg/#{NAME}-#{VERS}.tgz}
View
4 lib/sequel_core/adapters/ado.rb → lib/sequel/adapters/ado.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/utils/date_format'
+Sequel.require 'adapters/utils/date_format'
require 'win32ole'
module Sequel
@@ -20,7 +20,7 @@ def initialize(opts)
opts[:driver] ||= 'SQL Server'
case opts[:driver]
when 'SQL Server'
- require 'sequel_core/adapters/shared/mssql'
+ Sequel.require 'adapters/shared/mssql'
extend Sequel::MSSQL::DatabaseMethods
end
end
View
0  lib/sequel_core/adapters/db2.rb → lib/sequel/adapters/db2.rb
File renamed without changes
View
0  lib/sequel_core/adapters/dbi.rb → lib/sequel/adapters/dbi.rb
File renamed without changes
View
6 lib/sequel_core/adapters/do.rb → lib/sequel/adapters/do.rb
@@ -15,19 +15,19 @@ module DataObjects
# given database object so it supports the correct database type.
DATABASE_SETUP = {:postgres=>proc do |db|
require 'do_postgres'
- require 'sequel_core/adapters/do/postgres'
+ Sequel.require 'adapters/do/postgres'
db.converted_exceptions << PostgresError
db.extend(Sequel::DataObjects::Postgres::DatabaseMethods)
end,
:mysql=>proc do |db|
require 'do_mysql'
- require 'sequel_core/adapters/do/mysql'
+ Sequel.require 'adapters/do/mysql'
db.converted_exceptions << MysqlError
db.extend(Sequel::DataObjects::MySQL::DatabaseMethods)
end,
:sqlite3=>proc do |db|
require 'do_sqlite3'
- require 'sequel_core/adapters/do/sqlite'
+ Sequel.require 'adapters/do/sqlite'
db.converted_exceptions << Sqlite3Error
db.extend(Sequel::DataObjects::SQLite::DatabaseMethods)
end
View
2  lib/sequel_core/adapters/do/mysql.rb → lib/sequel/adapters/do/mysql.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/mysql'
+Sequel.require 'adapters/shared/mysql'
module Sequel
module DataObjects
View
2  lib/sequel_core/adapters/do/postgres.rb → lib/sequel/adapters/do/postgres.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/postgres'
+Sequel.require 'adapters/shared/postgres'
module Sequel
Postgres::CONVERTED_EXCEPTIONS << PostgresError
View
2  lib/sequel_core/adapters/do/sqlite.rb → lib/sequel/adapters/do/sqlite.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/sqlite'
+Sequel.require 'adapters/shared/sqlite'
module Sequel
module DataObjects
View
2  lib/sequel_core/adapters/firebird.rb → lib/sequel/adapters/firebird.rb
@@ -1,5 +1,5 @@
require 'fb'
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require 'adapters/utils/unsupported'
module Sequel
# The Sequel Firebird adapter requires the ruby fb driver located at
View
2  lib/sequel_core/adapters/informix.rb → lib/sequel/adapters/informix.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require 'adapters/utils/unsupported'
require 'informix'
module Sequel
View
14 lib/sequel_core/adapters/jdbc.rb → lib/sequel/adapters/jdbc.rb
@@ -1,5 +1,5 @@
require 'java'
-require 'sequel_core/adapters/utils/stored_procedures'
+Sequel.require 'adapters/utils/stored_procedures'
module Sequel
# Houses Sequel's JDBC support when running on JRuby.
@@ -35,35 +35,35 @@ module JavaSQL
# Contains procs keyed on sub adapter type that extend the
# given database object so it supports the correct database type.
DATABASE_SETUP = {:postgresql=>proc do |db|
- require 'sequel_core/adapters/jdbc/postgresql'
+ Sequel.require 'adapters/jdbc/postgresql'
db.extend(Sequel::JDBC::Postgres::DatabaseMethods)
JDBC.load_gem('postgres')
org.postgresql.Driver
end,
:mysql=>proc do |db|
- require 'sequel_core/adapters/jdbc/mysql'
+ Sequel.require 'adapters/jdbc/mysql'
db.extend(Sequel::JDBC::MySQL::DatabaseMethods)
JDBC.load_gem('mysql')
com.mysql.jdbc.Driver
end,
:sqlite=>proc do |db|
- require 'sequel_core/adapters/jdbc/sqlite'
+ Sequel.require 'adapters/jdbc/sqlite'
db.extend(Sequel::JDBC::SQLite::DatabaseMethods)
JDBC.load_gem('sqlite3')
org.sqlite.JDBC
end,
:oracle=>proc do |db|
- require 'sequel_core/adapters/jdbc/oracle'
+ Sequel.require 'adapters/jdbc/oracle'
db.extend(Sequel::JDBC::Oracle::DatabaseMethods)
Java::oracle.jdbc.driver.OracleDriver
end,
:sqlserver=>proc do |db|
- require 'sequel_core/adapters/shared/mssql'
+ Sequel.require 'adapters/shared/mssql'
db.extend(Sequel::MSSQL::DatabaseMethods)
com.microsoft.sqlserver.jdbc.SQLServerDriver
end,
:h2=>proc do |db|
- require 'sequel_core/adapters/jdbc/h2'
+ Sequel.require 'adapters/jdbc/h2'
db.extend(Sequel::JDBC::H2::DatabaseMethods)
JDBC.load_gem('h2')
org.h2.Driver
View
3  lib/sequel_core/adapters/jdbc/h2.rb → lib/sequel/adapters/jdbc/h2.rb
@@ -1,5 +1,4 @@
-require 'sequel_core/adapters/utils/date_format'
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require %w'date_format unsupported', 'adapters/utils'
module Sequel
module JDBC
View
2  lib/sequel_core/adapters/jdbc/mysql.rb → lib/sequel/adapters/jdbc/mysql.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/mysql'
+Sequel.require 'adapters/shared/mysql'
module Sequel
module JDBC
View
2  lib/sequel_core/adapters/jdbc/oracle.rb → lib/sequel/adapters/jdbc/oracle.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/oracle'
+Sequel.require 'adapters/shared/oracle'
module Sequel
module JDBC
View
2  lib/sequel_core/adapters/jdbc/postgresql.rb → lib/sequel/adapters/jdbc/postgresql.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/postgres'
+Sequel.require 'adapters/shared/postgres'
module Sequel
Postgres::CONVERTED_EXCEPTIONS << NativeException
View
2  lib/sequel_core/adapters/jdbc/sqlite.rb → lib/sequel/adapters/jdbc/sqlite.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/sqlite'
+Sequel.require 'adapters/shared/sqlite'
module Sequel
module JDBC
View
3  lib/sequel_core/adapters/mysql.rb → lib/sequel/adapters/mysql.rb
@@ -1,6 +1,5 @@
require 'mysql'
-require 'sequel_core/adapters/shared/mysql'
-require 'sequel_core/adapters/utils/stored_procedures'
+Sequel.require %w'shared/mysql utils/stored_procedures', 'adapters'
module Sequel
# Module for holding all MySQL-related classes and modules for Sequel.
View
4 lib/sequel_core/adapters/odbc.rb → lib/sequel/adapters/odbc.rb
@@ -12,10 +12,10 @@ def initialize(opts)
super(opts)
case opts[:db_type]
when 'mssql'
- require 'sequel_core/adapters/shared/mssql'
+ Sequel.require 'adapters/shared/mssql'
extend Sequel::MSSQL::DatabaseMethods
when 'progress'
- require 'sequel_core/adapters/shared/progress'
+ Sequel.require 'adapters/shared/progress'
extend Sequel::Progress::DatabaseMethods
end
end
View
0  lib/sequel_core/adapters/openbase.rb → lib/sequel/adapters/openbase.rb
File renamed without changes
View
2  lib/sequel_core/adapters/oracle.rb → lib/sequel/adapters/oracle.rb
@@ -1,5 +1,5 @@
require 'oci8'
-require 'sequel_core/adapters/shared/oracle'
+Sequel.require 'adapters/shared/oracle'
module Sequel
module Oracle
View
2  lib/sequel_core/adapters/postgres.rb → lib/sequel/adapters/postgres.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/shared/postgres'
+Sequel.require 'adapters/shared/postgres'
begin
require 'pg'
View
2  lib/sequel_core/adapters/shared/mssql.rb → lib/sequel/adapters/shared/mssql.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require 'adapters/utils/unsupported'
module Sequel
module MSSQL
View
10 lib/sequel_core/adapters/shared/mysql.rb → lib/sequel/adapters/shared/mysql.rb
@@ -1,11 +1,9 @@
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require 'adapters/utils/unsupported'
module Sequel
- module Schema
- module SQL
- # Keep default column_references_sql for add_foreign_key support
- alias default_column_references_sql column_references_sql
- end
+ class Database
+ # Keep default column_references_sql for add_foreign_key support
+ alias default_column_references_sql column_references_sql
end
module MySQL
class << self
View
3  lib/sequel_core/adapters/shared/oracle.rb → lib/sequel/adapters/shared/oracle.rb
@@ -1,5 +1,4 @@
-require 'sequel_core/adapters/utils/date_format'
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require %w'date_format unsupported', 'adapters/utils'
module Sequel
module Oracle
View
0  lib/sequel_core/adapters/shared/postgres.rb → lib/sequel/adapters/shared/postgres.rb
File renamed without changes
View
3  lib/sequel_core/adapters/shared/progress.rb → lib/sequel/adapters/shared/progress.rb
@@ -1,5 +1,4 @@
-require 'sequel_core/adapters/utils/date_format'
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require %w'date_format unsupported', 'adapters/utils'
module Sequel
module Progress
View
2  lib/sequel_core/adapters/shared/sqlite.rb → lib/sequel/adapters/shared/sqlite.rb
@@ -1,4 +1,4 @@
-require 'sequel_core/adapters/utils/unsupported'
+Sequel.require 'adapters/utils/unsupported'
module Sequel
module SQLite
View
2  lib/sequel_core/adapters/sqlite.rb → lib/sequel/adapters/sqlite.rb
@@ -1,5 +1,5 @@
require 'sqlite3'
-require 'sequel_core/adapters/shared/sqlite'
+Sequel.require 'adapters/shared/sqlite'
module Sequel
# Top level module for holding all SQLite-related modules and classes
View
0  lib/sequel_core/adapters/utils/date_format.rb → lib/sequel/adapters/utils/date_format.rb
File renamed without changes
View
0  lib/sequel_core/adapters/utils/stored_procedures.rb → lib/sequel/adapters/utils/stored_procedures.rb
File renamed without changes
View
0  lib/sequel_core/adapters/utils/unsupported.rb → lib/sequel/adapters/utils/unsupported.rb
File renamed without changes
View
0  lib/sequel_core/connection_pool.rb → lib/sequel/connection_pool.rb
File renamed without changes
View
204 lib/sequel/core.rb
@@ -0,0 +1,204 @@
+%w'bigdecimal bigdecimal/util date enumerator thread time uri yaml'.each do |f|
+ require f
+end
+
+# Top level module for Sequel
+#
+# There are some class methods that are added via metaprogramming, one for
+# each supported adapter. For example:
+#
+# DB = Sequel.sqlite # Memory database
+# DB = Sequel.sqlite('blog.db')
+# DB = Sequel.postgres('database_name', :user=>'user',
+# :password=>'password', :host=>'host', :port=>5432,
+# :max_connections=>10)
+#
+# If a block is given to these methods, it is passed the opened Database
+# object, which is closed (disconnected) when the block exits. For example:
+#
+# Sequel.sqlite('blog.db'){|db| puts db.users.count}
+#
+# Sequel converts the column type tinyint to a boolean by default,
+# you can override the conversion to use tinyint as an integer:
+#
+# Sequel.convert_tinyint_to_bool = false
+#
+# Sequel converts two digit years in Dates and DateTimes by default,
+# so 01/02/03 is interpreted at January 2nd, 2003, and 12/13/99 is interpreted
+# as December 13, 1999.. You can override this # to treat those dates as
+# January 2nd, 0003 and December 13, 0099, respectively, by setting:
+#
+# Sequel.convert_two_digit_years = false
+#
+# Sequel can use either Time or DateTime for times returned from the
+# database. It defaults to Time. To change it to DateTime, use:
+#
+# Sequel.datetime_class = DateTime
+#
+# Sequel currently does not use instance_eval for virtual row blocks by default
+# (e.g. the block passed to Dataset#filter, #select, #order and other similar
+# methods). If you want to use instance_eval for these blocks, don't have any
+# block arguments, and set:
+#
+# Sequel.virtual_row_instance_eval = true
+#
+# When this is set, you can do:
+#
+# dataset.filter{|o| o.column > 0} # no instance_eval
+# dataset.filter{column > 0} # instance eval
+#
+# When the virtual_row_instance_eval is false, using a virtual row block without a block
+# argument will generate a deprecation message.
+#
+# The option to not use instance_eval for a block with no arguments will be removed in a future version.
+# If you have any virtual row blocks that you don't want to use instance_eval for,
+# make sure the blocks have block arguments.
+module Sequel
+ @convert_tinyint_to_bool = true
+ @convert_two_digit_years = true
+ @datetime_class = Time
+ @virtual_row_instance_eval = false
+
+ class << self
+ attr_accessor :convert_tinyint_to_bool, :convert_two_digit_years, :datetime_class, :virtual_row_instance_eval
+ end
+
+ # Creates a new database object based on the supplied connection string
+ # and optional arguments. The specified scheme determines the database
+ # class used, and the rest of the string specifies the connection options.
+ # For example:
+ #
+ # DB = Sequel.connect('sqlite:/') # Memory database
+ # DB = Sequel.connect('sqlite://blog.db') # ./blog.db
+ # DB = Sequel.connect('sqlite:///blog.db') # /blog.db
+ # DB = Sequel.connect('postgres://user:password@host:port/database_name')
+ # DB = Sequel.connect('sqlite:///blog.db', :max_connections=>10)
+ #
+ # If a block is given, it is passed the opened Database object, which is
+ # closed when the block exits. For example:
+ #
+ # Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}
+ def self.connect(*args, &block)
+ Database.connect(*args, &block)
+ end
+
+ # Set the method to call on identifiers going into the database. This affects
+ # the literalization of identifiers by calling this method on them before they are input.
+ # Sequel upcases identifiers in all SQL strings for most databases, so to turn that off:
+ #
+ # Sequel.identifier_input_method = nil
+ #
+ # to downcase instead:
+ #
+ # Sequel.identifier_input_method = :downcase
+ #
+ # Other string methods work as well.
+ def self.identifier_input_method=(value)
+ Database.identifier_input_method = value
+ end
+
+ # Set the method to call on identifiers coming out of the database. This affects
+ # the literalization of identifiers by calling this method on them when they are
+ # retrieved from the database. Sequel downcases identifiers retrieved for most
+ # databases, so to turn that off:
+ #
+ # Sequel.identifier_output_method = nil
+ #
+ # to upcase instead:
+ #
+ # Sequel.identifier_output_method = :upcase
+ #
+ # Other string methods work as well.
+ def self.identifier_output_method=(value)
+ Database.identifier_output_method = value
+ end
+
+ # Set whether to quote identifiers for all databases by default. By default,
+ # Sequel quotes identifiers in all SQL strings, so to turn that off:
+ #
+ # Sequel.quote_identifiers = false
+ def self.quote_identifiers=(value)
+ Database.quote_identifiers = value
+ end
+
+ # Require all given files which should be in the same or a subdirectory of
+ # this file
+ def self.require(files, subdir=nil)
+ Array(files).each{|f| super("#{File.dirname(__FILE__)}/#{"#{subdir}/" if subdir}#{f}")}
+ end
+
+ # Set whether to set the single threaded mode for all databases by default. By default,
+ # Sequel uses a threadsafe connection pool, which isn't as fast as the
+ # single threaded connection pool. If your program will only have one thread,
+ # and speed is a priority, you may want to set this to true:
+ #
+ # Sequel.single_threaded = true
+ def self.single_threaded=(value)
+ Database.single_threaded = value
+ end
+
+ # Converts a string into a Date object.
+ def self.string_to_date(s)
+ begin
+ Date.parse(s, Sequel.convert_two_digit_years)
+ rescue => e
+ raise Error::InvalidValue, "Invalid Date value '#{self}' (#{e.message})"
+ end
+ end
+
+ # Converts a string into a Time or DateTime object, depending on the
+ # value of Sequel.datetime_class.
+ def self.string_to_datetime(s)
+ begin
+ if datetime_class == DateTime
+ DateTime.parse(s, convert_two_digit_years)
+ else
+ datetime_class.parse(s)
+ end
+ rescue => e
+ raise Error::InvalidValue, "Invalid #{datetime_class} value '#{self}' (#{e.message})"
+ end
+ end
+
+ # Converts a string into a Time object.
+ def self.string_to_time(s)
+ begin
+ Time.parse(s)
+ rescue => e
+ raise Error::InvalidValue, "Invalid Time value '#{self}' (#{e.message})"
+ end
+ end
+
+ ### Private Class Methods ###
+
+ # Helper method that the database adapter class methods that are added to Sequel via
+ # metaprogramming use to parse arguments.
+ def self.adapter_method(adapter, *args, &block) # :nodoc:
+ raise(::Sequel::Error, "Wrong number of arguments, 0-2 arguments valid") if args.length > 2
+ opts = {:adapter=>adapter.to_sym}
+ opts[:database] = args.shift if args.length >= 1 && !(args[0].is_a?(Hash))
+ if Hash === (arg = args[0])
+ opts.merge!(arg)
+ elsif !arg.nil?
+ raise ::Sequel::Error, "Wrong format of arguments, either use (), (String), (Hash), or (String, Hash)"
+ end
+ connect(opts, &block)
+ end
+
+ # Method that adds a database adapter class method to Sequel that calls
+ # Sequel.adapter_method.
+ def self.def_adapter_method(*adapters) # :nodoc:
+ adapters.each do |adapter|
+ instance_eval("def #{adapter}(*args, &block); adapter_method('#{adapter}', *args, &block) end")
+ end
+ end
+
+ private_class_method :adapter_method, :def_adapter_method
+
+ require(%w"metaprogramming core_ext sql core_sql connection_pool exceptions dataset migration database object_graph version deprecated")
+ require(%w"schema_generator schema_methods schema_sql", 'database')
+ require(%w"convenience prepared_statements sql", 'dataset')
+
+ # Add the database adapter class methods to Sequel via metaprogramming
+ def_adapter_method(*Database::ADAPTERS)
+end
View
0  lib/sequel_core/core_ext.rb → lib/sequel/core_ext.rb
File renamed without changes
View
0  lib/sequel_core/core_sql.rb → lib/sequel/core_sql.rb
File renamed without changes
View
4 lib/sequel_core/database.rb → lib/sequel/database.rb
@@ -1,5 +1,3 @@
-%w'methods generator sql'.each{|f| require "sequel_core/database/schema_#{f}"}
-
module Sequel
# Array of all databases to which Sequel has connected. If you are
# developing an application that can connect to an arbitrary number of
@@ -101,7 +99,7 @@ def self.adapter_class(scheme)
if (klass = @@adapters[scheme]).nil?
# attempt to load the adapter file
begin
- require "sequel_core/adapters/#{scheme}"
+ Sequel.require "adapters/#{scheme}"
rescue LoadError => e
raise Error::AdapterNotFound, "Could not load #{scheme} adapter:\n #{e.message}"
end
View
0  lib/sequel_core/database/schema_generator.rb → lib/sequel/database/schema_generator.rb
File renamed without changes
View
0  lib/sequel_core/database/schema_methods.rb → lib/sequel/database/schema_methods.rb
File renamed without changes
View
0  lib/sequel_core/database/schema_sql.rb → lib/sequel/database/schema_sql.rb
File renamed without changes
View
4 lib/sequel_core/dataset.rb → lib/sequel/dataset.rb
@@ -1,7 +1,3 @@
-%w'convenience prepared_statements sql'.each do |f|
- require "sequel_core/dataset/#{f}"
-end
-
module Sequel
# A Dataset represents a view of a the data in a database, constrained by
# specific parameters such as filtering conditions, order, etc. Datasets
View
0  lib/sequel_core/dataset/convenience.rb → lib/sequel/dataset/convenience.rb
File renamed without changes
View
0  lib/sequel_core/dataset/prepared_statements.rb → lib/sequel/dataset/prepared_statements.rb
File renamed without changes
View
0  lib/sequel_core/dataset/sql.rb → lib/sequel/dataset/sql.rb
File renamed without changes
View
0  lib/sequel_core/deprecated.rb → lib/sequel/deprecated.rb
File renamed without changes
View
0  lib/sequel_core/exceptions.rb → lib/sequel/exceptions.rb
File renamed without changes
View
0  lib/sequel_core/metaprogramming.rb → lib/sequel/metaprogramming.rb
File renamed without changes
View
0  lib/sequel_core/migration.rb → lib/sequel/migration.rb
File renamed without changes
View
0  lib/sequel_core/object_graph.rb → lib/sequel/object_graph.rb
File renamed without changes
View
0  lib/sequel_core/sql.rb → lib/sequel/sql.rb
File renamed without changes
View
0  lib/sequel_core/version.rb → lib/sequel/version.rb
File renamed without changes
View
199 lib/sequel_core.rb
@@ -1,198 +1 @@
-%w'bigdecimal bigdecimal/util date enumerator thread time uri yaml'.each do |f|
- require f
-end
-%w"metaprogramming core_ext sql core_sql connection_pool exceptions
- dataset migration database object_graph version deprecated".each do |f|
- require "sequel_core/#{f}"
-end
-
-# Top level module for Sequel
-#
-# There are some class methods that are added via metaprogramming, one for
-# each supported adapter. For example:
-#
-# DB = Sequel.sqlite # Memory database
-# DB = Sequel.sqlite('blog.db')
-# DB = Sequel.postgres('database_name', :user=>'user',
-# :password=>'password', :host=>'host', :port=>5432,
-# :max_connections=>10)
-#
-# If a block is given to these methods, it is passed the opened Database
-# object, which is closed (disconnected) when the block exits. For example:
-#
-# Sequel.sqlite('blog.db'){|db| puts db.users.count}
-#
-# Sequel converts the column type tinyint to a boolean by default,
-# you can override the conversion to use tinyint as an integer:
-#
-# Sequel.convert_tinyint_to_bool = false
-#
-# Sequel converts two digit years in Dates and DateTimes by default,
-# so 01/02/03 is interpreted at January 2nd, 2003, and 12/13/99 is interpreted
-# as December 13, 1999.. You can override this # to treat those dates as
-# January 2nd, 0003 and December 13, 0099, respectively, by setting:
-#
-# Sequel.convert_two_digit_years = false
-#
-# Sequel can use either Time or DateTime for times returned from the
-# database. It defaults to Time. To change it to DateTime, use:
-#
-# Sequel.datetime_class = DateTime
-#
-# Sequel currently does not use instance_eval for virtual row blocks by default
-# (e.g. the block passed to Dataset#filter, #select, #order and other similar
-# methods). If you want to use instance_eval for these blocks, don't have any
-# block arguments, and set:
-#
-# Sequel.virtual_row_instance_eval = true
-#
-# When this is set, you can do:
-#
-# dataset.filter{|o| o.column > 0} # no instance_eval
-# dataset.filter{column > 0} # instance eval
-#
-# When the virtual_row_instance_eval is false, using a virtual row block without a block
-# argument will generate a deprecation message.
-#
-# The option to not use instance_eval for a block with no arguments will be removed in a future version.
-# If you have any virtual row blocks that you don't want to use instance_eval for,
-# make sure the blocks have block arguments.
-module Sequel
- @convert_tinyint_to_bool = true
- @convert_two_digit_years = true
- @datetime_class = Time
- @virtual_row_instance_eval = false
-
- class << self
- attr_accessor :convert_tinyint_to_bool, :convert_two_digit_years, :datetime_class, :virtual_row_instance_eval
- end
-
- # Creates a new database object based on the supplied connection string
- # and optional arguments. The specified scheme determines the database
- # class used, and the rest of the string specifies the connection options.
- # For example:
- #
- # DB = Sequel.connect('sqlite:/') # Memory database
- # DB = Sequel.connect('sqlite://blog.db') # ./blog.db
- # DB = Sequel.connect('sqlite:///blog.db') # /blog.db
- # DB = Sequel.connect('postgres://user:password@host:port/database_name')
- # DB = Sequel.connect('sqlite:///blog.db', :max_connections=>10)
- #
- # If a block is given, it is passed the opened Database object, which is
- # closed when the block exits. For example:
- #
- # Sequel.connect('sqlite://blog.db'){|db| puts db[:users].count}
- def self.connect(*args, &block)
- Database.connect(*args, &block)
- end
-
- # Set the method to call on identifiers going into the database. This affects
- # the literalization of identifiers by calling this method on them before they are input.
- # Sequel upcases identifiers in all SQL strings for most databases, so to turn that off:
- #
- # Sequel.identifier_input_method = nil
- #
- # to downcase instead:
- #
- # Sequel.identifier_input_method = :downcase
- #
- # Other string methods work as well.
- def self.identifier_input_method=(value)
- Database.identifier_input_method = value
- end
-
- # Set the method to call on identifiers coming out of the database. This affects
- # the literalization of identifiers by calling this method on them when they are
- # retrieved from the database. Sequel downcases identifiers retrieved for most
- # databases, so to turn that off:
- #
- # Sequel.identifier_output_method = nil
- #
- # to upcase instead:
- #
- # Sequel.identifier_output_method = :upcase
- #
- # Other string methods work as well.
- def self.identifier_output_method=(value)
- Database.identifier_output_method = value
- end
-
- # Set whether to quote identifiers for all databases by default. By default,
- # Sequel quotes identifiers in all SQL strings, so to turn that off:
- #
- # Sequel.quote_identifiers = false
- def self.quote_identifiers=(value)
- Database.quote_identifiers = value
- end
-
- # Set whether to set the single threaded mode for all databases by default. By default,
- # Sequel uses a threadsafe connection pool, which isn't as fast as the
- # single threaded connection pool. If your program will only have one thread,
- # and speed is a priority, you may want to set this to true:
- #
- # Sequel.single_threaded = true
- def self.single_threaded=(value)
- Database.single_threaded = value
- end
-
- # Converts a string into a Date object.
- def self.string_to_date(s)
- begin
- Date.parse(s, Sequel.convert_two_digit_years)
- rescue => e
- raise Error::InvalidValue, "Invalid Date value '#{self}' (#{e.message})"
- end
- end
-
- # Converts a string into a Time or DateTime object, depending on the
- # value of Sequel.datetime_class.
- def self.string_to_datetime(s)
- begin
- if datetime_class == DateTime
- DateTime.parse(s, convert_two_digit_years)
- else
- datetime_class.parse(s)
- end
- rescue => e
- raise Error::InvalidValue, "Invalid #{datetime_class} value '#{self}' (#{e.message})"
- end
- end
-
- # Converts a string into a Time object.
- def self.string_to_time(s)
- begin
- Time.parse(s)
- rescue => e
- raise Error::InvalidValue, "Invalid Time value '#{self}' (#{e.message})"
- end
- end
-
- ### Private Class Methods ###
-
- # Helper method that the database adapter class methods that are added to Sequel via
- # metaprogramming use to parse arguments.
- def self.adapter_method(adapter, *args, &block) # :nodoc:
- raise(::Sequel::Error, "Wrong number of arguments, 0-2 arguments valid") if args.length > 2
- opts = {:adapter=>adapter.to_sym}
- opts[:database] = args.shift if args.length >= 1 && !(args[0].is_a?(Hash))
- if Hash === (arg = args[0])
- opts.merge!(arg)
- elsif !arg.nil?
- raise ::Sequel::Error, "Wrong format of arguments, either use (), (String), (Hash), or (String, Hash)"
- end
- connect(opts, &block)
- end
-
- # Method that adds a database adapter class method to Sequel that calls
- # Sequel.adapter_method.
- def self.def_adapter_method(*adapters) # :nodoc:
- adapters.each do |adapter|
- instance_eval("def #{adapter}(*args, &block); adapter_method('#{adapter}', *args, &block) end")
- end
- end
-
- private_class_method :adapter_method, :def_adapter_method
-
- # Add the database adapter class methods to Sequel via metaprogramming
- def_adapter_method(*Database::ADAPTERS)
-end
+require 'sequel/core'
View
2  lib/sequel_model.rb
@@ -1,4 +1,4 @@
-require 'sequel_core'
+require 'sequel/core'
module Sequel
# Holds the nameless subclasses that are created with
View
2  spec/adapters/spec_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
unless Object.const_defined?('Sequel')
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
- require 'sequel_core'
+ require 'sequel/core'
Sequel.quote_identifiers = false
end
begin
View
2  spec/extensions/spec_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
unless Object.const_defined?('Sequel')
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
- require 'sequel_core'
+ require 'sequel/core'
end
unless Sequel.const_defined?('Model')
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
View
2  spec/sequel_core/database_spec.rb
@@ -800,7 +800,7 @@ def disconnect
context "A broken adapter (lib is there but the class is not)" do
setup do
- @fn = File.join(File.dirname(__FILE__), '../../lib/sequel_core/adapters/blah.rb')
+ @fn = File.join(File.dirname(__FILE__), '../../lib/sequel/adapters/blah.rb')
File.open(@fn,'a'){}
end
View
2  spec/sequel_core/spec_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
unless Object.const_defined?('Sequel')
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
- require 'sequel_core'
+ require 'sequel/core'
end
Sequel.virtual_row_instance_eval = true
View
2  spec/sequel_model/spec_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
unless Object.const_defined?('Sequel')
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
- require 'sequel_core'
+ require 'sequel/core'
end
unless Sequel.const_defined?('Model')
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
Please sign in to comment.
Something went wrong with that request. Please try again.