Class: Octostat::Database

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/octostat/database.rb

Constant Summary collapse

PRAGMAS =
{
  "foreign_keys" => true,
  "journal_mode" => :wal,
  "synchronous" => :normal,
  "mmap_size" => 134217728, # 128 megabytes
  "journal_size_limit" => 67108864, # 64 megabytes
  "cache_size" => 2000
}
COMMIT_INSERT =
"INSERT OR IGNORE INTO commits (hash, email, name, date, merge_commit, subject) VALUES (?, ?, ?, ?, ?, ?)"

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Database

Returns a new instance of Database.



19
20
21
22
23
24
# File 'lib/octostat/database.rb', line 19

def initialize file
  @db = SQLite3::Database.new file
  apply_pragma
  create_tables
  @commit_statement = db.prepare(COMMIT_INSERT)
end

Instance Method Details

#insert_commit(hash:, name:, email:, subject:, date:, merge_commit:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/octostat/database.rb', line 26

def insert_commit hash:, name:, email:, subject:, date:, merge_commit:
  commit_statement.execute([
    hash,
    email,
    name,
    date,
    (merge_commit ? 1 : 0),
    subject
  ])
end