Module: Honker

Defined in:
lib/honker.rb,
lib/honker/lock.rb,
lib/honker/stream.rb,
lib/honker/railtie.rb,
lib/honker/version.rb,
lib/honker/scheduler.rb,
lib/honker/transaction.rb

Defined Under Namespace

Classes: CoreWatcher, Database, Error, ExtensionResolver, Job, Lock, Outbox, Queue, Railtie, ScheduledFire, Scheduler, Stream, StreamEvent, Transaction

Constant Summary collapse

DEFAULT_PRAGMAS =
<<~SQL
  PRAGMA journal_mode = WAL;
  PRAGMA synchronous = NORMAL;
  PRAGMA busy_timeout = 5000;
  PRAGMA mmap_size = 0;
  PRAGMA foreign_keys = ON;
  PRAGMA cache_size = -32000;
  PRAGMA temp_store = MEMORY;
  PRAGMA wal_autocheckpoint = 10000;
SQL
VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.bootstrap(sqlite_conn) ⇒ Object

Run honker_bootstrap() on the connection. Idempotent. Separated from load_extension so production users can opt to bootstrap from a migration instead of every connect.



99
100
101
# File 'lib/honker.rb', line 99

def self.bootstrap(sqlite_conn)
  sqlite_conn.execute("SELECT honker_bootstrap()")
end

.extension_path(override = nil) ⇒ Object

Resolve the bundled (or overridden) extension path without naming ExtensionResolver — useful for database.yml ERB and tooling.



81
82
83
# File 'lib/honker.rb', line 81

def self.extension_path(override = nil)
  ExtensionResolver.new.resolve(override)
end

.load_extension(sqlite_conn, extension_path: nil) ⇒ Object

Load the Honker extension onto a raw SQLite3::Database. Encapsulates the enable_load_extension(true)/load/enable_load_extension(false) sequence so the toggle-off can't be forgotten.



88
89
90
91
92
93
94
# File 'lib/honker.rb', line 88

def self.load_extension(sqlite_conn, extension_path: nil)
  resolved = ExtensionResolver.new.resolve(extension_path)
  sqlite_conn.enable_load_extension(true)
  sqlite_conn.load_extension(resolved)
ensure
  sqlite_conn.enable_load_extension(false)
end

.sequel_after_connect(extension_path: nil, bootstrap: true) ⇒ Object

Returns a Proc suitable for Sequel/Rom/Hanami after_connect:.



111
112
113
# File 'lib/honker.rb', line 111

def self.sequel_after_connect(extension_path: nil, bootstrap: true)
  proc { |conn| setup(conn, extension_path: extension_path, bootstrap: bootstrap) }
end

.setup(sqlite_conn, extension_path: nil, bootstrap: true) ⇒ Object

Convenience: load the extension then bootstrap. The one-liner most ORM integrations reach for.



105
106
107
108
# File 'lib/honker.rb', line 105

def self.setup(sqlite_conn, extension_path: nil, bootstrap: true)
  load_extension(sqlite_conn, extension_path: extension_path)
  self.bootstrap(sqlite_conn) if bootstrap
end