Ruby ORM integration
Rails and ActiveRecord can load SQLite extensions through the sqlite3 gem configuration. Once loaded, Honker calls are ordinary SQL inside ActiveRecord::Base.transaction.
ActiveRecord (Rails)
Section titled “ActiveRecord (Rails)”As of the sqlite3 gem 2.4+ and Rails PR #53827, extensions are declared in config/database.yml:
Wiring
Section titled “Wiring”default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 extensions: - /path/to/libhonker_ext
development: <<: *default database: storage/app.dbRun SELECT honker_bootstrap() once from an initializer or migration:
Rails.application.config.after_initialize do ActiveRecord::Base.connection.execute("SELECT honker_bootstrap()")endWrapper
Section titled “Wrapper”module Honker def self.enqueue(queue, payload, delay: nil, priority: 0, max_attempts: 3) sql = ActiveRecord::Base.sanitize_sql_array([ "SELECT honker_enqueue(?, ?, NULL, ?, ?, ?, NULL) AS id", queue, payload.to_json, delay, priority, max_attempts ]) ActiveRecord::Base.connection.select_value(sql) end
def self.notify(channel, payload = nil) sql = ActiveRecord::Base.sanitize_sql_array([ "SELECT notify(?, ?)", channel, payload ? payload.to_json : nil ]) ActiveRecord::Base.connection.execute(sql) endendActiveRecord::Base.transaction do Order.create!(user_id: 42) Honker.enqueue("emails", { to: "alice@example.com" }) Honker.notify("orders", { id: 42 })endWorkers run as a separate process using the honker Ruby gem.