diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2023-02-22 23:03:34 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2023-02-22 23:15:41 +0900 |
commit | 9310cff78765b2a8588aaa19e8fb10d6183f0979 (patch) | |
tree | 3cfd42440105a9daa9b41f4998742049672c26b1 /sqlite.cr | |
parent | 2833849c77f1fdf5d95d88b928cc50b348d032dc (diff) | |
download | hybring-9310cff78765b2a8588aaa19e8fb10d6183f0979.tar.gz |
Read configuration file
Diffstat (limited to 'sqlite.cr')
-rw-r--r-- | sqlite.cr | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/sqlite.cr b/sqlite.cr index 7df496b..4cca647 100644 --- a/sqlite.cr +++ b/sqlite.cr @@ -50,18 +50,18 @@ class Database class Statement def initialize(db, query) bytes = query.to_slice - Database.check SQLite.prepare db.ref, bytes, bytes.size, + Database.check SQLite.prepare db, bytes, bytes.size, out @ref, out @tail end - def ref - @ref - end - def step : LibC::Int SQLite.step @ref end + def row + Row.new @ref + end + def finalize Database.check SQLite.finalize @ref end @@ -102,20 +102,19 @@ class Database self.exec SCHEMA do end self.exec "PRAGMA user_version = #{MIGRATIONS.size}" do end end + rescue ex + self.finalize + raise ex end end - def ref - @ref - end - def exec(query : String) - stmt = Statement.new self, query + stmt = Statement.new @ref, query loop do rc = stmt.step case rc when SQLite::ROW - yield Row.new stmt.ref + yield stmt.row when SQLite::DONE break else @@ -124,6 +123,14 @@ class Database end end + def members + result = [] of Tuple(String, String, String) + self.exec "SELECT nick, opennic, icann FROM member" do |row| + result << {row[0].text, row[1].text, row[2].text} + end + result + end + def finalize Database.check SQLite.close @ref end |