diff examples/blog/src/lib/Post.luan @ 1220:4721c482c86b

cleaner Db example
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 21 Mar 2018 15:54:57 -0600
parents 1f9d34a6f308
children 709f7498a363
line wrap: on
line diff
--- a/examples/blog/src/lib/Post.luan	Wed Mar 21 15:36:54 2018 -0600
+++ b/examples/blog/src/lib/Post.luan	Wed Mar 21 15:54:57 2018 -0600
@@ -6,7 +6,7 @@
 local now = Time.now or error()
 local String = require "luan:String.luan"
 local trim = String.trim or error()
-local Db = require "site:/lib/Db.luan"
+local db = require("site:/lib/Db.luan").db or error()
 
 
 local Post = {}
@@ -33,7 +33,7 @@
 			content = this.content
 			date = this.date
 		}
-		Db.save(doc)
+		db.save(doc)
 		this.id = doc.id
 	end
 
@@ -41,12 +41,12 @@
 end
 
 function Post.get_by_id(id)
-	local doc = Db.get_document("id:"..id)
+	local doc = db.get_document("id:"..id)
 	return doc and from_doc(doc)
 end
 
 function Post.get_all()
-	local docs = Db.search("type:post",1,1000,"id desc")
+	local docs = db.search("type:post",1,1000,"id desc")
 	local posts = {}
 	for _, doc in ipairs(docs) do
 		posts[#posts+1] = from_doc(doc)
@@ -59,7 +59,7 @@
 	if #query == 0 then
 		return Post.get_all()
 	end
-	local docs = Db.search(query,1,1000)
+	local docs = db.search(query,1,1000)
 	local posts = {}
 	for _, doc in ipairs(docs) do
 		posts[#posts+1] = from_doc(doc)