aboutsummaryrefslogtreecommitdiff
path: root/src/guff/model.cr
blob: 515af4e1f7738c8792e9521677c6ec165dd04333 (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
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    : Proc(Hash(String, ::SQLite3::Value), Nil) \
    )
      @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 template(
      key   : Symbol,
      args  : Hash(String, String) | Nil
    )
      @db.template(key, args)
    end
  end
end