aboutsummaryrefslogtreecommitdiff
path: root/src/guff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-06 18:24:25 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-06 18:24:25 -0500
commite7e975568d596810b74e207e73426624c215bb24 (patch)
tree31545fe22b7df8694e5434998e57b2bde7b9ef65 /src/guff
parentb89d53220afee70a991fe8c3ec694e32f1954ea0 (diff)
downloadold-guff-e7e975568d596810b74e207e73426624c215bb24.tar.bz2
old-guff-e7e975568d596810b74e207e73426624c215bb24.zip
populate get_posts
Diffstat (limited to 'src/guff')
-rw-r--r--src/guff/post-model.cr27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/guff/post-model.cr b/src/guff/post-model.cr
index e0e82a4..112589b 100644
--- a/src/guff/post-model.cr
+++ b/src/guff/post-model.cr
@@ -1,5 +1,32 @@
module Guff
class PostModel < Model
+ SQL = {
+ get_posts: "
+ SELECT a.post_id,
+ a.name,
+ a.body,
+ a.html
+
+ FROM posts a
+ JOIN (
+ SELECT DISTICT
+ c.post_id
+
+ FROM post_tags c
+
+ JOIN tags d
+ ON (d.tag_id = c.tag_id)
+ JOIN (VALUES (%{tags}) e(name)
+ ON (e.name = d.name)
+ ) b
+
+ WHERE c.%{filter}
+
+ ORDER BY %{sort} %{dir}
+ OFFSET ? LIMIT ?
+ ",
+ }
+
def get_posts(req)
# TODO
[{foo: "bar"}, {foo: "asdf"}]