annotate src/lib/Db.luan @ 2:ee1f91e67509

add Db
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 24 Oct 2024 15:37:35 -0600
parents
children 2da10ece826f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local new_error = Luan.new_error or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Lucene = require "luan:lucene/Lucene.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local uri = Io.uri or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Thread = require "luan:Thread.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Time = require "luan:Time.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Logging = require "luan:logging/Logging.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local logger = Logging.logger "Db"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local dir = uri("site:/private/local/lucene")
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local Db = Lucene.index( dir, {
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 log_dir = uri("site:/private/local/lucene_log")
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 name = "lucene"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 version = 1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 } )
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Db.indexed_fields.user_email = Lucene.type.lowercase
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 function Db.not_in_transaction()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 logger.error(new_error("not in transaction"))
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 Db.update{
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 }
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 if Http.is_serving then
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1} } )
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 return Db