annotate examples/blog/src/lib/Db.luan @ 1392:002152af497a

hosted postgres
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 06 Sep 2019 00:19:47 -0600
parents 94f48cc76de8
children cc0dbca576dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 599
diff changeset
1 local Lucene = require "luan:lucene/Lucene.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 599
diff changeset
2 local Io = require "luan:Io.luan"
1392
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
3 local Hosting = require "luan:host/Hosting.luan"
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
4 local Logging = require "luan:logging/Logging.luan"
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
5 local logger = Logging.logger "Db"
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
1220
4721c482c86b cleaner Db example
Franklin Schmidt <fschmidt@gmail.com>
parents: 1088
diff changeset
8 local Db = {}
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
1392
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
10 local postgres_spec = Hosting.postgres_spec and Hosting.postgres_spec()
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
11 logger.info("postgres_spec="..postgres_spec)
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
12 if postgres_spec ~= nil then
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
13 function postgres_spec.completer(doc)
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
14 return doc
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
15 end
1387
bc40bc9aab3a start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1369
diff changeset
16 end
bc40bc9aab3a start postgres backup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1369
diff changeset
17
1224
Franklin Schmidt <fschmidt@gmail.com>
parents: 1220
diff changeset
18 function Db.new(lucene_dir)
1369
709f7498a363 change Lucene.index() and add Lucene.recover()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1224
diff changeset
19 local dir = Io.uri(lucene_dir)
1392
002152af497a hosted postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1391
diff changeset
20 local db = Lucene.index( dir, Lucene.type.english, {"subject","content"}, postgres_spec )
596
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 -- this is how you index a field
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 -- db.indexed_fields.post_date = Lucene.type.long
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return db
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
6bb0c83116e9 add blog sample app
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
1224
Franklin Schmidt <fschmidt@gmail.com>
parents: 1220
diff changeset
28 Db.db = Db.new("site:/private/local/lucene")
1220
4721c482c86b cleaner Db example
Franklin Schmidt <fschmidt@gmail.com>
parents: 1088
diff changeset
29
1388
2024d23ddd64 add restore_from_postgres
Franklin Schmidt <fschmidt@gmail.com>
parents: 1387
diff changeset
30 --Db.db.restore_from_postgres()
1391
94f48cc76de8 add lucene check
Franklin Schmidt <fschmidt@gmail.com>
parents: 1388
diff changeset
31 Db.db.check()
1220
4721c482c86b cleaner Db example
Franklin Schmidt <fschmidt@gmail.com>
parents: 1088
diff changeset
32 return Db