aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-06 19:17:30 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-06 19:17:30 -0500
commit70e294e312710eb1e89c9cacd09a830e05d4bbe9 (patch)
tree3032297644592c4abe8100ed8770b05f5a44583a
parent884afe538a5de60fd5638a87620d3cfa00d90f6f (diff)
downloadold-guff-70e294e312710eb1e89c9cacd09a830e05d4bbe9.tar.bz2
old-guff-70e294e312710eb1e89c9cacd09a830e05d4bbe9.zip
add template database
-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