Class Sequel::Amalgalite::Database
In: lib/sequel/adapters/amalgalite.rb
Parent: Sequel::Database

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

Methods

Included Modules

::Sequel::SQLite::DatabaseMethods

Public Instance methods

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).

[Source]

    # File lib/sequel/adapters/amalgalite.rb, line 66
66:       def connect(server)
67:         opts = server_opts(server)
68:         opts[:database] = ':memory:' if blank_object?(opts[:database])
69:         db = ::Amalgalite::Database.new(opts[:database])
70:         db.busy_handler(::Amalgalite::BusyTimeout.new(opts.fetch(:timeout, 5000)/50, 50))
71:         db.type_map = SequelTypeMap.new
72:         db
73:       end

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

[Source]

    # File lib/sequel/adapters/amalgalite.rb, line 76
76:       def database_type
77:         :sqlite
78:       end

Return instance of Sequel::Amalgalite::Dataset with the given options.

[Source]

    # File lib/sequel/adapters/amalgalite.rb, line 81
81:       def dataset(opts = nil)
82:         Amalgalite::Dataset.new(self, opts)
83:       end

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

[Source]

     # File lib/sequel/adapters/amalgalite.rb, line 102
102:       def execute(sql, opts={})
103:         retried = false
104:         _execute(sql, opts) do |conn|
105:           conn.prepare(sql) do |stmt|
106:             begin
107:              stmt.result_meta
108:             rescue NoMethodError
109:               conn.reload_schema!
110:               stmt.result_meta
111:             end
112:             yield stmt
113:           end
114:         end
115:       end

Run the given SQL with the given arguments and reload the schema. Returns nil.

[Source]

    # File lib/sequel/adapters/amalgalite.rb, line 86
86:       def execute_ddl(sql, opts={})
87:         _execute(sql, opts){|conn| conn.execute_batch(sql); conn.reload_schema!}
88:         nil
89:       end

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

[Source]

    # File lib/sequel/adapters/amalgalite.rb, line 92
92:       def execute_dui(sql, opts={})
93:         _execute(sql, opts){|conn| conn.execute_batch(sql); conn.row_changes}
94:       end

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

[Source]

    # File lib/sequel/adapters/amalgalite.rb, line 97
97:       def execute_insert(sql, opts={})
98:         _execute(sql, opts){|conn| conn.execute_batch(sql); conn.last_insert_rowid}
99:       end

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

[Source]

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

Use the native driver transaction method if there isn‘t already a transaction in progress on the connection, always yielding a connection inside a transaction transaction.

[Source]

     # File lib/sequel/adapters/amalgalite.rb, line 125
125:       def transaction(opts={})
126:         synchronize(opts[:server]) do |conn|
127:           return yield(conn) if conn.in_transaction?
128:           begin
129:             result = nil
130:             log_info('Transaction.begin')
131:             conn.transaction{result = yield(conn)}
132:             result
133:           rescue ::Exception => e
134:             log_info('Transaction.rollback')
135:             transaction_error(e, ::Amalgalite::Error, ::Amalgalite::SQLite3::Error)
136:           ensure
137:             log_info('Transaction.commit') unless e
138:           end
139:         end
140:       end

[Validate]