Included Modules

Class Index [+]

Quicksearch

Sequel::Amalgalite::Database

Database class for SQLite databases used with Sequel and the amalgalite driver.

Public Instance Methods

connect(server) click to toggle source

Connect to the database. Since SQLite is a file based database, the only options available are :database (to specify the database name), and :timeout, to specify how long to wait for the database to be available if it is locked, given in milliseconds (default is 5000).

    # File lib/sequel/adapters/amalgalite.rb, line 76
76:       def connect(server)
77:         opts = server_opts(server)
78:         opts[:database] = ':memory:' if blank_object?(opts[:database])
79:         db = ::Amalgalite::Database.new(opts[:database])
80:         db.busy_handler(::Amalgalite::BusyTimeout.new(opts.fetch(:timeout, 5000)/50, 50))
81:         db.type_map = SequelTypeMap.new(self)
82:         connection_pragmas.each{|s| log_yield(s){db.execute_batch(s)}}
83:         db
84:       end
database_type() click to toggle source

Amalgalite is just the SQLite database without a separate SQLite installation.

    # File lib/sequel/adapters/amalgalite.rb, line 87
87:       def database_type
88:         :sqlite
89:       end
execute(sql, opts={}) click to toggle source

Run the given SQL with the given arguments and yield each row.

     # File lib/sequel/adapters/amalgalite.rb, line 108
108:       def execute(sql, opts={})
109:         _execute(sql, opts) do |conn|
110:           begin
111:             yield(stmt = log_yield(sql){conn.prepare(sql)})
112:           ensure
113:             stmt.close if stmt
114:           end
115:         end
116:       end
execute_ddl(sql, opts={}) click to toggle source

Run the given SQL with the given arguments. Returns nil.

    # File lib/sequel/adapters/amalgalite.rb, line 92
92:       def execute_ddl(sql, opts={})
93:         _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}}
94:         nil
95:       end
execute_dui(sql, opts={}) click to toggle source

Run the given SQL with the given arguments and return the number of changed rows.

     # File lib/sequel/adapters/amalgalite.rb, line 98
 98:       def execute_dui(sql, opts={})
 99:         _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.row_changes}
100:       end
execute_insert(sql, opts={}) click to toggle source

Run the given SQL with the given arguments and return the last inserted row id.

     # File lib/sequel/adapters/amalgalite.rb, line 103
103:       def execute_insert(sql, opts={})
104:         _execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.last_insert_rowid}
105:       end
single_value(sql, opts={}) click to toggle source

Run the given SQL with the given arguments and return the first value of the first row.

     # File lib/sequel/adapters/amalgalite.rb, line 119
119:       def single_value(sql, opts={})
120:         _execute(sql, opts){|conn| log_yield(sql){conn.first_value_from(sql)}}
121:       end

Private Instance Methods

_execute(sql, opts) click to toggle source

Yield an available connection. Rescue any Amalgalite::Errors and turn them into DatabaseErrors.

     # File lib/sequel/adapters/amalgalite.rb, line 127
127:       def _execute(sql, opts)
128:         begin
129:           synchronize(opts[:server]){|conn| yield conn}
130:         rescue ::Amalgalite::Error, ::Amalgalite::SQLite3::Error => e
131:           raise_error(e)
132:         end
133:       end
connection_pool_default_options() click to toggle source

The Amagalite adapter does not need the pool to convert exceptions. Also, force the max connections to 1 if a memory database is being used, as otherwise each connection gets a separate database.

     # File lib/sequel/adapters/amalgalite.rb, line 138
138:       def connection_pool_default_options
139:         o = super.dup
140:         # Default to only a single connection if a memory database is used,
141:         # because otherwise each connection will get a separate database
142:         o[:max_connections] = 1 if @opts[:database] == ':memory:' || blank_object?(@opts[:database])
143:         o
144:       end
database_error_classes() click to toggle source

Both main error classes that Amalgalite raises

     # File lib/sequel/adapters/amalgalite.rb, line 147
147:       def database_error_classes
148:         [::Amalgalite::Error, ::Amalgalite::SQLite3::Error]
149:       end
disconnect_connection(c) click to toggle source

Disconnect given connections from the database.

     # File lib/sequel/adapters/amalgalite.rb, line 152
152:       def disconnect_connection(c)
153:         c.close
154:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.