Skip to content

Instantly share code, notes, and snippets.

@seki
Created August 27, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seki/1e74ce4e196d2d4ef9ce619212743ec1 to your computer and use it in GitHub Desktop.
Save seki/1e74ce4e196d2d4ef9ce619212743ec1 to your computer and use it in GitHub Desktop.
sqlite3-util.rb
class SQLite3::Database
def statement(s)
if @cache.nil?
@cache = Hash.new { |h, k| h[k] = self.prepare(k) }
end
@cache[s]
end
end
class SQLite3::Statement
def get_first_row(*bind_vars)
execute(*bind_vars).first
end
def get_first_value(*bind_vars)
execute(*bind_vars).each { |row| return row[0] }
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment