Sha256: 77260b443220fb4b8614bb7a99f41b3c2110fffaa4266607aff4819b16d50a7e

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

require_relative './extralite_ext'

# Extralite is a Ruby gem for working with SQLite databases
module Extralite
  # A base class for Extralite exceptions
  class Error < RuntimeError
  end

  # An exception representing an SQL error emitted by SQLite
  class SQLError < Error
  end

  # An exception raised when an SQLite database is busy (locked by another
  # thread or process)
  class BusyError < Error
  end

  # An SQLite database
  class Database
    alias_method :execute, :query

    TABLES_SQL = <<~SQL
      SELECT name FROM sqlite_schema
      WHERE type ='table'
        AND name NOT LIKE 'sqlite_%';
    SQL

    def tables
      query_single_column(TABLES_SQL)
    end

    def pragma(value)
      value.is_a?(Hash) ? pragma_set(value) : pragma_get(value)
    end

    def pragma_set(values)
      sql = values.inject(+'') { |s, (k, v)| s += "pragma #{k}=#{v}; " }
      query(sql)
    end

    def pragma_get(key)
      query("pragma #{key}")
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
extralite-bundle-1.16 lib/extralite.rb
extralite-1.16 lib/extralite.rb