diff examples/blog/src/lib/Db.luan @ 1429:82415c9c0015

move versioning into Lucene
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 24 Nov 2019 23:07:21 -0700
parents 732b5de211fc
children 13135e289b50
line wrap: on
line diff
--- a/examples/blog/src/lib/Db.luan	Sun Nov 24 21:02:38 2019 -0700
+++ b/examples/blog/src/lib/Db.luan	Sun Nov 24 23:07:21 2019 -0700
@@ -10,8 +10,6 @@
 local logger = Logging.logger "Db"
 
 
-local Db = {}
-
 local postgres_spec = Hosted.postgres_spec()
 --logger.info(stringify(postgres_spec))
 
@@ -19,25 +17,23 @@
 	return doc
 end
 
-function Db.new(lucene_dir)
-	local dir = Io.uri(lucene_dir)
-	local db = Lucene.index( dir, {
-		version = "2"
-		default_type = Lucene.type.english
-		default_fields = {"subject","content"}
-		completer = completer
-		postgres_spec = postgres_spec
-	} )
-	
+local dir = Io.uri("site:/private/local/lucene")
+local Db = Lucene.index( dir, {
+	default_type = Lucene.type.english
+	default_fields = {"subject","content"}
+	completer = completer
+	postgres_spec = postgres_spec
+} )
+
 --	this is how you index a field
 --	db.indexed_fields.post_date = Lucene.type.long
 
-	return db
-end
-
-Db.db = Db.new("site:/private/local/lucene")
-
-Db.db.restore_from_postgres()
-Thread.schedule( Db.db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } )
+Db.restore_from_postgres()
+Db.update{
+	[1] = function()
+		logger.info "update"
+	end
+}
+Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1}, id="blog-db-check" } )
 
 return Db