annotate src/lib/Db.luan @ 4:2da10ece826f

add Chat
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 27 Oct 2024 20:39:18 -0600
parents ee1f91e67509
children f9e6a4cc4f7d
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
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
24 Db.indexed_fields.chat_user_ids = Lucene.type.long
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
25 Db.indexed_fields.chat_updated = Lucene.type.long
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
26
2
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 function Db.not_in_transaction()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 logger.error(new_error("not in transaction"))
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 Db.update{
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 }
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 if Http.is_serving then
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1} } )
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 return Db