class Litequeue

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/litequeue.rbs

class Litequeue
  def extract_row: (Array[Array, String, String] results) -> Array[String]
  def pop: (queue: String, limit: Integer) -> Array[String]
end

def self.configuration

def self.configuration
  @configuration ||= Configuration.new(
    _path = "queue.sqlite3",
    _synchronous = :OFF,
    _mmap_size = 32 * 1024
  )
end

def self.configure

def self.configure
  yield(configuration)
end

def self.migrations

def self.migrations
  YAML.load_file("#{__dir__}/litequeue/migrations.sql.yml")
end

def self.statements

def self.statements
  YAML.load_file("#{__dir__}/litequeue/statements.sql.yml")
end

def clear(queue: nil)

def clear(queue: nil)
  results = @db.run_statement(:clear, queue)
  results.count
end

def count(queue: nil)

def count(queue: nil)
  results = @db.run_statement(:count, queue)
  extract_value(results)
end

def delete(id)

def delete(id)
  results = @db.run_statement(:delete, id)
  extract_value(results)
end

def empty?

def empty?
  count.zero?
end

def extract_row(results) # [[{value}, {value}]] || []

Experimental RBS support (using type sampling data from the type_fusion project).

def extract_row: ( results) -> String

This signature was generated using 42 samples from 3 applications.

[[{value}, {value}]] || []
def extract_row(results) # [[{value}, {value}]] || []
  return if results.empty?
  results
    .first # [[value, value]] -> [value, value]
end

def extract_value(results) # [["{value}"]] || []

[["{value}"]] || []
def extract_value(results) # [["{value}"]] || []
  return if results.empty?
  results
    .first # [[value]] -> [value]
    .first # [value] -> value
end

def initialize

def initialize
  configuration = self.class.configuration
  file = configuration.path
  options = configuration.to_h
    .slice(:synchronous, :mmap_size, :journal_size_limit)
    .merge(migrations: self.class.migrations,
      statements: self.class.statements)
  @db = Litedb::Connection.new(file, options)
  # Once the instance has been initialized, don't allow the configuration to be changed
  # as it won't have any effect.
  configuration.freeze
end

def pop(queue: DEFAULT_QUEUE, limit: 1)

Experimental RBS support (using type sampling data from the type_fusion project).

def pop: (queue: String, limit: Integer) -> String

This signature was generated using 38 samples from 3 applications.

def pop(queue: DEFAULT_QUEUE, limit: 1)
  results = @db.run_statement(:pop, queue, limit)
  return extract_row(results) if limit == 1
  results
end

def push(value, queue: DEFAULT_QUEUE, delay: 0)

def push(value, queue: DEFAULT_QUEUE, delay: 0)
  results = @db.run_statement(:push, queue, delay, value) # [["{id}", "{name}"]]
  extract_row(results)
end

def repush(id, value, queue: DEFAULT_QUEUE, delay: 0)

def repush(id, value, queue: DEFAULT_QUEUE, delay: 0)
  results = @db.run_statement(:repush, id, queue, delay, value)
  extract_value(results)
end