aboutsummaryrefslogtreecommitdiff
path: root/src/guff/model.cr
blob: bd3562936daa22793a4b4e0bea6e1ffcd5907174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Guff
  class Model
    getter :db

    def initialize(@models : Models, @templates : TemplateCache)
      @db = TemplateDatabase.new(@models.db, @templates)
    end

    def one(
      key       : Symbol,
      args      : Array(String) | Hash(String, String) | Nil,
      tmpl_args : Hash(String, String) | Nil
    )
      @db.one(key, args, tmpl_args)
    end

    def row(
      key       : Symbol,
      args      : Array(String) | Hash(String, String) | Nil,
      tmpl_args : Hash(String, String) | Nil
    )
      @db.row(key, args, tmpl_args)
    end

    def all(
      key       : Symbol,
      args      : Array(String) | Hash(String, String) | Nil,
      tmpl_args : Hash(String, String) | Nil,
      &block    : Hash(String, ::SQLite3::Value) -> \
    )
      @db.all(key, args, tmpl_args, &block)
    end

    def query(
      key       : Symbol,
      args      : Array(String) | Hash(String, String) | Nil,
      tmpl_args : Hash(String, String) | Nil
    )
      @db.query(key, args, tmpl_args)
    end

    def transaction(&block)
      @db.transaction(&block)
    end

    def template(
      key   : Symbol,
      args  : Hash(String, String) | Nil
    )
      @db.template(key, args)
    end

    def last_insert_row_id
      @db.last_insert_row_id
    end
  end
end