From 70e294e312710eb1e89c9cacd09a830e05d4bbe9 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 6 Mar 2016 19:17:30 -0500 Subject: add template database --- src/guff/template-database.cr | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/guff/template-database.cr (limited to 'src/guff') 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 -- cgit v1.2.3