aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/guff/template-database.cr46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/guff/template-database.cr b/src/guff/template-database.cr
new file mode 100644
index 0000000..2232de3
--- /dev/null
+++ b/src/guff/template-database.cr
@@ -0,0 +1,46 @@
+module Guff
+ class TemplateDatabase
+ def initialize(@db : Database, @templates : TemplateCache)
+ end
+
+ def one(
+ key : Symbol,
+ args : Array(String) | Hash(String, String) | Nil,
+ tmpl_args : Hash(String, String)?
+ )
+ @db.one(sql_for(key, tmpl_args), args)
+ end
+
+ def row(
+ key : Symbol,
+ args : Array(String) | Hash(String, String) | Nil,
+ tmpl_args : Hash(String, String)?,
+ )
+ @db.row(sql_for(key, tmpl_args), args)
+ end
+
+ def all(
+ key : Symbol,
+ args : Array(String) | Hash(String, String) | Nil,
+ tmpl_args : Hash(String, String)?,
+ &block : Proc(Hash(String, ::SQLite3::Value), Nil) \
+ )
+ @db.all(sql_for(key, tmpl_args), args, &block)
+ end
+
+ def query(
+ key : Symbol,
+ args : Array(String) | Hash(String, String) | Nil,
+ tmpl_args : Hash(String, String)?
+ )
+ @db.query(sql_for(key, tmpl_args), args)
+ end
+
+ private def sql_for(
+ key : Symbol,
+ args : Hash(String, String)?
+ )
+ @templates[key].run(args)
+ end
+ end
+end