-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.nim
40 lines (33 loc) · 1.01 KB
/
store.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import norm/sqlite, times, options, json
import webconfig
db(DB_FILE, "", "", ""):
type
Note* = object
content*: string
tagline*: string
created*: DateTime
updated*: Option[DateTime]
deleted*: Option[DateTime]
NoteHistory* = object
noteId*: int
content*: string
tagline*: string
created*: DateTime
updated*: Option[DateTime]
deleted*: Option[DateTime]
proc setup*() =
withDb:
createTables(force=true)
proc `%`*(t: DateTime): JsonNode =
return %(t.toTime().toUnix())
proc searchNotes*(searchTerms: string): seq[Note] =
withDb:
return Note.getAll(cond="""
(content like '%' || ? || '%'
OR tagline like '%' || ? || '%')
AND content not like '@archive'
AND tagline not like '@archive'
ORDER BY created desc
""", params=[?searchTerms, ?searchTerms])
when isMainModule:
setup()